Forum: Ruby on Rails customizing layouts for functions

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
cranberry (Guest)
on 2006-02-21 13:53
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!
James A. (Guest)
on 2006-02-21 13:58
(Received via mailing list)
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 <removed_email_address@domain.invalid> wrote:
> but rails ddin't like this.
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
* J *
  ~
cranberry (Guest)
on 2006-02-21 14:04
James A. 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.
cranberry (Guest)
on 2006-02-21 16:02
cranberry wrote:
> James A. 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?
Ben M. (Guest)
on 2006-02-21 18:56
(Received via mailing list)
cranberry wrote:
> 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
This topic is locked and can not be replied to.