3

I just deployed one of my apps to heroku. This app uses :

  • A default "myapp.herokuapp.com" address,
  • And I got a domain configured so that the app can be reached through "www.myapp.com".

And I noticed today the following issue : my application links are based on "http://myapp.herokuapp.com" domain (hence I get "http://myapp.herokuapp.com/page" URLs) even when I access the app using my domain name (I would then expect to get "www.myapp.com/page" URLs).

I tried to edit my production.rb and set the default_url_options :

# Base domain for url generation 
config.action_controller.default_url_options = { :host => "www.myapp.com" }

But it doesn't change a thing. Also tried to change this in application.rb, just in case, but nothing happens either.

Any clue ? Thanks a lot for your help guys !

Edit : This used to work as expected before today when I did the database migration to the new Heroku postgres thing. Don't know if this can have any impact.

4
  • Default rails would use the domain you accessed on, are you using some kind of page/fragment caching which could have cached the herokuapp.com links? Commented Aug 11, 2012 at 18:39
  • @JohnBeynon, thanks for your suggestion. Didn't think of this but I'm not using any kind of caching anyway. Commented Aug 11, 2012 at 18:57
  • 1
    so the code for your links, are you using _path or _url? Commented Aug 11, 2012 at 20:35
  • _path for my links. Is that what you meant by caching ? Commented Aug 11, 2012 at 20:57

2 Answers 2

2

If you're using _path methods for your urls, this is generating a relative path which is always based on the url you visit. If you're using controller/fragment caching, you should probably use _url instead in your views. You might also want to consider setting config.action_controller.perform_caching to false in your production.rb if all your pages have some controller logic.

See this page for more info on how caching works in Rails.

Sign up to request clarification or add additional context in comments.

1 Comment

Mmh, don't really manage to understand why using _path used to work and doesn't work anymore. Anyway, I replaced my "visible" links by their _url equivalent, and I'm then presented with the links in the format I was looking for. Thanks for your help !
0

I had a similar problem. It was caused by the following line of code which was pointing to heroku.com and getting redirected to herokuapp.com

  config.action_mailer.default_url_options = { :host => 'my-staging-domain.heroku.com' }

I mention it because it's the action_mailer.default_url_options yet clearly it affects the default url options outside of the scope of the mailer if you haven't explicitly set up the action_controller.default_url_options

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.