I have a PagesController with a layout 'pages.html.erb' specified.
class PagesController < Spree::StoreController
layout 'pages'
respond_to :html
def lifestyle
render 'lifestyle'
end
def co_step_1
render 'co_step_1'
end
def co_step_2
render 'co_step_2'
end
end
Is it possible to have an additional method in PagesController that uses a different layout?
In other words i want to override the layout 'pages.html.erb'
in an additional method.
A bit different answer from the others. No need for before actions or similar, just use a layout
and method to distinguish which layout to use, like:
class PagesController < Spree::StoreController
layout :resolve_layout
respond_to :html
def lifestyle
render 'lifestyle'
end
def co_step_1
render 'co_step_1'
end
def co_step_2
render 'co_step_2'
end
private
def resolve_layout
action_name == 'pages' ? 'pages' : 'custom_layout'
end
end
Or whatever logic you want to use to decide which layout to use.
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