Dave Smith
2008-Dec-22 13:23 UTC
Passing aariable from controller to a different view ????
Hi Guys, I am still very new to this rails stuff so I''m looking for some help. I have a login controller which authenticates a person and redirects them to the projects page, here is a snippet of code. =====================================================================if request.post? person = Person.authenticate(params[:email_address], params[:password]) if person session["user_id"] = person.id if person.type == "Customer" flash[:notice] = "You have successfully logged in" redirect_to(:controller => "projects", :action => "index" ) end else redirect_to :action => "login" flash[:notice] = "Invalid user/password combination" end end ===================================================================== I have a projects controller which has a field company_id (as a project belongs to a company). I also have a people table which holds the customers (as well as admins based on person.type). I want to be able to redirect the person to the projects table and have the projects displayed only for that user. In the customer model I have specified belongs_to :company. In the project model I have also specified belongs_to :company. In the company model I have specified has_many :projects. Somehow I need to get the person logging in from the login controller and transfer that to company controller and then pass that to the the projects controller to use in the project view. But I have really stuck on how to do this! Please can someone help! Regards, Dave -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Ryan Bigg
2008-Dec-22 13:53 UTC
Re: Passing aariable from controller to a different view ????
Use restful authentication (or a similar plugin) for tracking that kind of stuff: http://github.com/technoweenie/restful_authentication ----- Ryan Bigg Freelancer http://frozenplague.net On 22/12/2008, at 11:53 PM, Dave Smith wrote:> > Hi Guys, > > I am still very new to this rails stuff so I''m looking for some > help. I > have a login controller which authenticates a person and redirects > them > to the projects page, here is a snippet of code. > > =====================================================================> if request.post? > person = Person.authenticate(params[:email_address], > params[:password]) > if person > session["user_id"] = person.id > if person.type == "Customer" > flash[:notice] = "You have successfully logged in" > redirect_to(:controller => "projects", :action => "index" > ) > end > else > redirect_to :action => "login" > flash[:notice] = "Invalid user/password combination" > end > end > =====================================================================> > I have a projects controller which has a field company_id (as a > project > belongs to a company). I also have a people table which holds the > customers (as well as admins based on person.type). > > I want to be able to redirect the person to the projects table and > have > the projects displayed only for that user. > > In the customer model I have specified belongs_to :company. > In the project model I have also specified belongs_to :company. > In the company model I have specified has_many :projects. > > Somehow I need to get the person logging in from the login controller > and transfer that to company controller and then pass that to the the > projects controller to use in the project view. > > But I have really stuck on how to do this! > > Please can someone help! > > Regards, > > Dave > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Dave Smith
2008-Dec-22 14:49 UTC
Re: Passing aariable from controller to a different view ???
Ryan Bigg wrote:> Use restful authentication (or a similar plugin) for tracking that > kind of stuff: http://github.com/technoweenie/restful_authentication > ----- > Ryan Bigg > Freelancer > http://frozenplague.netCouldnt I just do the following... in my projects controller? before_filter :find_projects def index # @projects = Project.find(:all) # @project_company = @projects.company_id @projects = @results.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @projects } end end def find_projects @user_in = Person.find_by_id(session["user_id"]) @company = Company.find_by_id(@user_in.company_id) @results = Company.find(@company.id).projects # Find all projects that belong to company end -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---