Fix for Streamlined menu rendering in Rails 2

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

# roles_helper.rb
def streamlined_side_menu
  # different stuff here

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.

2 thoughts on “Fix for Streamlined menu rendering in Rails 2

  1. Wouldn’t the better solution (since you’re involved in Streamlined and have some influence there) at least longer-term, be to fix Streamlined so that it doesn’t do this on Rails 2? (Or am I missing something?)

  2. Yes, that would definitely be the best solution. I did notify the rest of the team about the problem, and Rob opened a ticket for it. Our desire is to completely replace the current way Streamlined menus operate though, because frankly, overriding a method in a helper is just a weird way to control the menus to begin with.

Comments are closed.