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.

Named routes outside of controller/view confusion

#4217

Here is quote from http://github.com/rails/rails/blob/master/actionpack/lib/action_dis...

    # This generates, among other things, the method <tt>users_path</tt>. By default,
    # this method is accessible from your controllers, views and mailers. If you need
    # to access this auto-generated method from other places (such as a model), then
    # you can do that by including ActionController::UrlFor in your class:
    #
    #   class User < ActiveRecord::Base
    #     include ActionController::UrlFor
    #
    #     def base_uri
    #       user_path(self)
    #     end
    #   end

This currently doesn't work, in contrast include Rails.application.routes.url_helpers does,
but is it the proper way to get routes generated outside of controller/view?

In any case docs is wrong on that one, attached patch which demonstrates
the change.

Reported by Evgeniy Dolzhenko · March 18th, 2010 @ 05:01 PM

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

Activity

  1. Felix Sun
    Felix Sun

    Also seems that these named routes helpers not available in action view templates, I have to do:

    
    module ApplicationHelper
      include Rails.application.routes.url_helpers
      
    end
    

    In my application, Is that should be included by default?

    March 19th, 2010 @ 06:39 AM

  2. Repository
  3. Yehuda Katz (wycats)
    Yehuda Katz (wycats)
    • Assigned user set to Yehuda Katz (wycats)
    • Milestone cleared.

    The helpers should be available in views. Can you make sure this is still true on master?

    March 27th, 2010 @ 08:00 AM

  4. Evgeniy Dolzhenko
    Evgeniy Dolzhenko

    Great, thanks!

    Helpers are indeed available in views for for me.

    March 27th, 2010 @ 09:50 AM

  5. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Low

    October 15th, 2010 @ 11:01 PM