ruby - Rendering Layouts without loading its inner layout in Rails -
im trying bring layout in html page by
render layout 'flatty' thing loads whole flatty layout. in flatty.html.erb renders _header,_footer , _sidebar.html.erb dont want load _sidebar.html.erb in particular page. how should render this?
maybe in controller action, can have flag indicating sidebar should not rendered. then, in flatty.html.erb file, check flag variable before render _sidebar.html.erb.
for example, if have controller action called flatty, add instance variable, @disable_sidebar, act flag.
def flatty @disable_sidebar = true # other code render layout: 'flatty' end then, in flatty.html.erb, add conditional before render sidebar (note ! negation in if statement:
<% if !@disable_sidebar %> <%= render "layouts/sidebar" %> <% end %> alternatively, in flatty.html.erb can check controller , action values in params hash, , don't render sidebar if matches controller's action:
<% if params[:controller]!="your_controller" , !params[:action].eql? "flatty" %> <%= render "layouts/sidebar" %> <% end %>
Comments
Post a Comment