I have a different subheader partial I want to render dependent on where I’m at in my application. How do I go about determining where I’m at via ruby? Or do I need to parse the URL?
Example :
If I’m at my root level I want to use /home/subheader, if I’m in controller ‘test’ I want to render /test/subheader, etc… etc…
basically looking for this part:
(in my application view)
<%- if ############ %>
<%= render :partial => '/home/subheader' %>
<%- elsif ########### %>
<%= render :partial => '/test/subheader' %>
<%- else %>
<%= render :partial => '/layouts/subheader' %>
<%- end %>
Thanks
You can use current_page?
or use the controller’s method controller_name
If you’re using this in a per-controller basis, you should probably need layouts or use different templates, rendering different partials depending in controller/action is a code smell.
P.S: You could also try to get the
params[:controller]andparams[:action]variables, but I am not sure if they are passed correctly if your route is non the standard/:controller/:action