This project is archived and is in readonly mode.

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
- 
            
         Samuel Kadolph July 29th, 2010 @ 08:33 PMAlso, shouldn't the url helpers be moved outside of the helpers check? I don't see why having helpers disabled in a controller should prevent the routes from being loaded. Attached is a patch to moves route helpers outside of the if for regular helpers and does it first to allow helpers to override url helpers. 
- 
            
         Luis Correa d'Almeida September 14th, 2010 @ 12:31 AMAny progress on this? Is this expected behavior or should we expect the behavior to be the same as in 2.3.8? 
- 
         Andrew White September 14th, 2010 @ 06:59 AM- Milestone cleared.
- State changed from new to open
- Assigned user set to Andrew White
- Importance changed from  to Low
 
- 
         
- 
         Repository October 26th, 2010 @ 02:36 PM- State changed from open to resolved
 (from [63b0d0e9d29522ae8dd6b58ea094b8bc54f7bf70]) Allow generated url helpers to be overriden [#5243 state:resolved] http://github.com/rails/rails/commit/63b0d0e9d29522ae8dd6b58ea094b8... 
- 
         Repository October 26th, 2010 @ 02:36 PM(from [4ba24ba043a00e61e97369e6664d5c0fcdbc0fe8]) Allow generated url helpers to be overriden [#5243 state:resolved] http://github.com/rails/rails/commit/4ba24ba043a00e61e97369e6664d5c... 
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>
People watching this ticket
Attachments
Referenced by
- 
         5243 
          Cannot override helpers generated by routes
        (from [63b0d0e9d29522ae8dd6b58ea094b8bc54f7bf70])
Allow g... 5243 
          Cannot override helpers generated by routes
        (from [63b0d0e9d29522ae8dd6b58ea094b8bc54f7bf70])
Allow g...
- 
         5243 
          Cannot override helpers generated by routes
        (from [4ba24ba043a00e61e97369e6664d5c0fcdbc0fe8])
Allow g... 5243 
          Cannot override helpers generated by routes
        (from [4ba24ba043a00e61e97369e6664d5c0fcdbc0fe8])
Allow g...
 Andrew White
      Andrew White
 Jeremy Kemper
      Jeremy Kemper
 Juanma Cervera
      Juanma Cervera