Posts Tagged ‘layouts’
Development, Ruby On Rails - Tuesday, October 3, 2006 14:03 - 0 Comments
Multiple layouts within the same controller in Ruby on Rails
Using more than one layout in a controller is as simple as placing the following code in your controller:
layout :choose_layout
private
def choose_layout
if [ 'signup', 'login' ].include? action_name
'login'
else
'admin'
end
end
When Rails goes to select the layout it wont find one named “choose_layout”, so it will look for an action with that name instead.
The action checks if the Rails variable action_name (which contains the name of the current action) matches either ’signup’ or ‘login’. If this is true then the ‘login’ layout is rendered otherwise ‘admin’ is.
Most Popular Content
- Firebug Lite 1.2; Now with improved lite-ness
- D///FEST 2008 Flash Visualization
- Refresh Seattle: Lessons Learned Designing Onehub
- Wallpaper*’s Architect Directory 2008
- WordPress for iPhone Available Now
- IE PNG Fix v1.0 / 2.0 Alpha 2
- MonoCase.
- HelloMe* - Portfolio of Till Wiedeck
- i3 Wordpress Theme (v1.7)
- Twitter Widget
- Function Icon Set
