ciembor
ciembor

Reputation: 7337

url_for doesn't respect default_url_options

I would like to get the url using url_for with host set in development.rb. But instead of this, I get www.example.com which isn't set anywhere in directory with application.

Connecting to database specified by database.yml
  MOPED: 127.0.0.1:27017 COMMAND      database=admin command={:ismaster=>1} (0.5023ms)
Loading development environment (Rails 3.2.13)
[1] pry(main)> ActionMailer::Base.default_url_options
=> {:host=>"asd:3000"}
[2] pry(main)> app.posts_url
=> "http://www.example.com/posts"
[3] pry(main)> 

Does anyone know why and where it come from?

Upvotes: 0

Views: 207

Answers (2)

lulalala
lulalala

Reputation: 17981

You set the options under ActionMailer, so it does not work under console context.

example.com is just Rails filling in the blanks when it is not available.

If you want to get url in development.rb, which is the same as console context, add this on top of development.rb:

Rails.application.routes.default_url_options[:host] = "asd:3000"

Upvotes: 0

Michael Lynch
Michael Lynch

Reputation: 1743

I believe that is just how rails outputs the data from the console. I tested it out myself and in console i get the same thing:

[1] pry(main)> app.projects_url
=> "http://www.example.com/projects"

And in my development.rb file, i specify my host as something else..

However, in my application, all routes resolve to the correct place.

Upvotes: 1

Related Questions