If I would like to use a layout for a certain action (say, the show action) that is different from the layout declared at the top of the controller.rb file, how could I do this? This must be possible in rails, but I cannot seem to find anything about it.
render :layout => 'otherlayout'
layout 'layout', :only => [:first_action, :second_action] layout 'second_layout', :only => [:third_action, :fourth_action]
Don's is right as well, just depends on your application which is more DRY (or DRY-er?)
EDIT My previous code is mistaken. You cannot specify the layout
function multiple times. I found this solution online for dynamic layout rendering:
class OrdersController < BaseController layout :determine_layout private def determine_layout %w(new).include?(action_name) ? "some_layout" : "public" end end
Source: apidock.com/rails/Actio...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With