This project is archived and is in readonly mode.

#5243 ✓resolved
Samuel Kadolph

Cannot override helpers generated by routes

Reported by Samuel Kadolph | July 29th, 2010 @ 08:11 PM | in 3.0.2

In rails 3 (at least b4 and rc), you can no longer override the helpers generated by routes with your own helper files.

Rails 2.3.8

map.resources :gizmos

module GizmosHelper
  def new_gizmo_path
    puts "You can see me in the server output"
    super
  end
end

Rails 3

resources :gizmos

module GizmosHelper
  def new_gizmo_path
    puts "You cannot see me in the server output"
    super
  end
end

The reason you can no longer override the route helpers is because the order in which the helpers are included into a view has changed. The relevant code is from actionpack-3.0.0.rc\lib\abstract_controller\rendering.rb:

module AbstractController
  module Rendering
    module ClassMethods
      def view_context_class
        @view_context_class ||= begin
          controller = self
          Class.new(ActionView::Base) do
            if controller.respond_to?(:_helpers)
              include controller._helpers

              if controller.respond_to?(:_routes)
                include controller._routes.url_helpers
              end

              # TODO: Fix RJS to not require this
              self.helpers = controller._helpers
            end
          end
        end
      end
    end
  end
end

To allow overriding the route generated helpers, all that needs to be changed is to put include controller._helpers after the if.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Referenced by

Pages