This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join us in building a kind, collaborative learning community via our updated
Code of Conduct.

#1 and #2 work great. Although #3 doesn't. #2 sounds like the best workaround. I'll leave the answer open to see if someone knows how to set this up from the config files. Thanks for your help!
– alfFeb 15 '12 at 18:42

If you're relying on url_helpers for something like ActiveModel::Serializers (at least the v0.9.* series) where you'll be generating URLs outside of the main Rails request/response flow, you'll also need to set the Rails.application.routes.default_url_options. I've done it like so,

I had this exact same issue and none of the configuration suggestions worked. Thing that left me confused is that url_helpers works just fine from other parts of the application (specifically helpers). So I shouldn't have to insert new configuration to be able to use them elsewhere.

My solution at the end of the day was to do this:

Rails.application.routes.url_helpers.athlete_url(athlete)

What I suspect, though I can't prove, is that including the url helpers manually with:

include Rails.application.routes.url_helpers

actually causes some included block to be executed. Doing so changes the configuration out from under the code trying to use it. By not including, but instead referring to it directly any 'included' blocks are not re-executed.

I'd love to know if anyone can explain if I'm on the right track or just making false assumptions.

Bottom line though, referring to the url_helpers with the full module/class path got the job done.