I want to be able to have different layouts in my rails program for different functions. For example, when a person first comes to the site the layout will have a link that says ''home'', ''login'', or register on the menu bar. Once the user logs in however, the layout will change. I want it to show the links ''account manager'', ''logout'', etc. I tried putting "layout ''layout-name'' " right after I define a function, but rails ddin''t like this. Any suggestions? Thank you! -- Posted via http://www.ruby-forum.com/.
You can either use render :layout => ''custom_layout'' in each of your actions, or in your controller itself: class MyController < ApplicationController layout :choose_layout def choose_layout # return the string based on the action in params or whatever end ... end - james On 2/21/06, cranberry <miriamraphael@yahoo.com> wrote:> I want to be able to have different layouts in my rails program for > different functions. > > For example, when a person first comes to the site the layout will have > a link that says ''home'', ''login'', or register on the menu bar. > > Once the user logs in however, the layout will change. I want it to show > the links ''account manager'', ''logout'', etc. > > I tried putting "layout ''layout-name'' " right after I define a function, > but rails ddin''t like this. > > Any suggestions? > > Thank you! > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- * J * ~
James Adam wrote:> You can either use > > render :layout => ''custom_layout'' > > in each of your actions, or in your controller itself: > > class MyController < ApplicationController > layout :choose_layout > def choose_layout > # return the string based on the action in params or whatever > end > ...Thank you! that is so easy. -- Posted via http://www.ruby-forum.com/.
cranberry wrote:> James Adam wrote: >> You can either use >> >> render :layout => ''custom_layout''But I have a few functions in the controller that each need their own separate layout .... isn''t there a way to specify in the function itself what the layout should be? I want the layout to be in the function itself, otherwise i have to go and find all the instances of in my program and add '':layout =>'' to them... Suggestions? -- Posted via http://www.ruby-forum.com/.
cranberry wrote:>>James Adam wrote: >> >>>You can either use >>> >>> render :layout => ''custom_layout'' > > But I have a few functions in the controller that each need their own > separate layout .... > > isn''t there a way to specify in the function itself what the layout > should be? I want the layout to be in the function itself, otherwise i > have to go and find all the instances of in my program and add '':layout > =>'' to them... >Look at James'' post again: "You can either use render :layout => ''custom_layout'' in *each of your actions*, or in your controller itself..." In other words, "action" = "function". (And actually, you should call them "methods" in Ruby... although in the rails controller case, we use each method as an "action".) b