As ActionController::Base#default_url_options is deprecated, I wonder how to set default url options in rails3. The default url options are not static but dependent of the current request.
http://apidock.com/rails/ActionController/Base/default_url_options
Thanks, Corin
For Rails 3 specifically, the canonical way to do it is by adding a
default_url_options
method to yourApplicationController
.I just had to figure this out myself, so I know it works.
This is adapted from the Rails 3 Guide:
http://guides.rubyonrails.org/v3.2.21/action_controller_overview.html#default_url_options
To set url options for current request use something like this in your controller:
Now, :profile => current_profile will be automerge to path/url parameters.
Example routing:
Just write:
and if current_profile has set to_param to 'lucas':
I believe the preferred method is to now tell the router to handle this:
You can put this line in either
routes.rb
or an initializer. Whichever you would prefer. You could even put it in your environment configs if the values change based on your environment.That apidock.com link is misleading. default_url_options is not deprecated.
http://guides.rubyonrails.org/action_controller_overview.html#default_url_options