Rails 3. 1+ in?, :
layout :layout_by_action_name
def layout_by_action_name
if action_name.in?('new','edit')
'layout_file'
else
'application'
end
end
Rails 4+ , :
layout ->{ action_name.in?('new','edit') ? 'layout_file' : 'application' }
, , :
def layout_by_action_name
case action_name
when 'new','edit'
'layout_file'
when 'delete'
'other_file'
else
'application'
end
end
, , , render:
def new
...
render layout: 'layout_file'
end
def edit
...
render layout: 'layout_file'
end
This last option may even be the best option if you redefine the layout for only a small number of actions, because it is very clear.
source
share