Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActionController::UrlWriter removed without deprecation

#4749

Including ActionController::UrlWriter in your class was a documented way to get access to named route helpers in 2.3.x. It's gone in beta3 without a deprecation.

It originally had a deprecation in action_controller/deprecations.rb, which was commented out in 226dfc2681c98deaf14e4ae82e973d1d5caedd68 and then removed entirely in 8689989a52fb673650c45322f060093678c6b91e (although action_controller.rb still has an autoload for it).

Reported by John Firebaugh · June 1st, 2010 @ 09:25 PM

State: resolved
Milestone: none
Assigned to: Yehuda Katz (wycats) Yehuda Katz (wycats)
Importance: Low

Activity

  1. Wincent Colaiuta
    Wincent Colaiuta

    Any idea on what the replacement for this is?

    Back in Rails 2 I found that my sweepers didn't have access to named URL helper methods when running under the test environment. So I got around this by doing:

    include ActionController::UrlWriter
    

    in my sweepers.

    Under Rails 3 I observe the same behaviour: named URL helper methods don't work in sweepers (they all return nil). I think this is because some method_missing magic is going on in actionpack/lib/action_controller/caching/sweeping.rb:

    def method_missing(method, *arguments, &block)
      return if @controller.nil?
      @controller.__send__(method, *arguments, &block)
    end
    

    For some reason, under the test environment, the helper methods are not included and there is no real @controller object here when the sweeper is called. So a sweeper which does something like:

    expire_page(product_path(product) + '.html')

    Ends up evaluating it like this:

    expire_path(nil + '.html')

    Which obviously doesn't work.

    No idea why, but under development and production environments, the helper methods are included, and so the "method_missing" stuff never kicks in and calls to methods like "product_path(product)" work fine in the sweeper.

    So this seems like long-standing behavior, and under Rails 2 I could work around it by explicitly including UrlWriter. Wondering what I should be doing to get the same kind of workaround in Rails 3.

    June 15th, 2010 @ 09:03 PM

  2. Wincent Colaiuta
    Wincent Colaiuta

    Ok, via some lucky grepping found this:

    # this is the Rails 2 way
    include ActionController::UrlWriter
    
    # this is the Rails 3 equivalent
    include Rails.application.routes.url_helpers
    

    June 15th, 2010 @ 09:11 PM

  3. John Firebaugh
    John Firebaugh
    • Assigned user set to Yehuda Katz (wycats)

    Yehuda added a deprecation; this ticked should be resolved.

    http://github.com/rails/rails/commit/84703be5ffe7d94fd33bfbdb45cb0b...

    August 11th, 2010 @ 12:48 AM

  4. José Valim
    José Valim
    • State changed from new to resolved
    • Importance changed from to Low

    August 12th, 2010 @ 02:52 PM