I've used this tutorial to highlight the current page in the menu. I have a pages controller with a few static pages, for the home page I simply have
def home
@title = 'Home'
and similar for contact pages etc.
Then in my main layout file I have <body class="<%= @title %>">
and this works fine to set the correct css, but how do I set @title for my other controllers where there's more than one action?
views:
26answers:
1
+1
A:
You can use before_filter
on a controller
class Home < ActionController::Base
before_filter :highlight
def index
#...
end
private
def highlight
@title = "Home"
end
end
ctshryock
2010-05-28 14:06:05
that just gives me an error "uninitialized constant ActiveSupport::Callbacks::Callback::Blog"
raphael_turtle
2010-05-28 14:12:44
Updated my example.
ctshryock
2010-05-28 14:16:02