ruby on rails - application.html.erb to render different partial depending on the page user is on -


i show different header menu depending on page of site user on. in rails' application.html.erb want like:

<% if "user op page x" %>   <%= render 'layouts/header1' %> <% else %>   <%= render 'layouts/header2' %> <% end %> 

but line <% if "user op page x" %> need be? is, there rails method specifies page?

couple things mention here. 1 is, put stuff in layouts alternative layouts application.html.erb, can render whole different template part of app. admin ui have different layout example.

for that's more of global partial app, typically create partials folder under views: app/views/partials , put _header1.html.erb , _header2.html.erb in there.

now rendering them, controller method comes in handy.

in view, update if statement to:

<% if controller_name == "the_controller" && action_name == "the_action" %>   <%= render partial: "partials/header1" %> <% else %>   <%= render partial: "partials/header2" %> <% end %> 

just change controller name , action name values need to. if need more inclusive that, (the header 2 should more 1 action or controller), recommend looking content_for.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -