I noticed an interesting side effect of the default behavior of Rails today. A fresh Rails 2.0.2 app includes a line in app/controllers/application.rb that looks like this:
helper :all # include all helpers, all the time
It looks innocuous enough, but this line can actually cause some unexpected behavior when overriding Streamlined’s streamlined_top_menu and streamlined_side_menu helper methods on a controller-by-controller basis.
I had two Streamlined controllers setup, one for users and one for roles. I defined the users side menu and the roles side menu to each have certain links, like so:
# users_helper.rb
def streamlined_side_menu
# stuff here
end
# roles_helper.rb
def streamlined_side_menu
# different stuff here
end
When I visited the users controller, I saw the menu contents for the users controller. When I visited the roles controller, however, I saw the menu contents for… the users controller. What was happening was that ALL the helpers were being loaded for each controller, which meant that the streamlined_side_menu method defined in the roles helper got overridden by the users helper since the users helper was loaded after the roles helper.
Removing helper: all fixed the problem for me.