I’ve put a <render :partial => “_menu”> in the layout/application.rhtml
file that is used as layout for all views. And in every view map, I then
define a _menu.rhtml partial.
This is of course not flexible enough, since when I want to change some
name, I have to make changes in all these files.
What is a better way?
I’ve put a <render :partial => “_menu”> in the layout/application.rhtml
file that is used as layout for all views. And in every view map, I then
define a _menu.rhtml partial.
This is of course not flexible enough, since when I want to change some
name, I have to make changes in all these files.
What is a better way?
I don’t know how you are getting your controller names, but you can use
a shared partial, and do
something like:
<% Dir[‘app/controllers/*.rb’ ].each do |filename|
controller_name = File.basename filename %>
<% if @controller.controller_name == controller_name %> %= controller_name %>
<% else %> <%= controller_name %>
<%end
end %>
@controller should be the controller that the request was made on,
did the trick.
One more question, I used the temporary variable controller_name because
I will need it in a lot of links. Should it be a regular variable or an
instance variable?