Working with routes from the Rails consoleEdit

Rails 3

Named routing helpers

Allow the use of named routing helpers like user_path() in the console:

include Rails.application.routes.url_helpers

You can also use the app object available on the console:


Rails 2

Named routes

This information can be found in a few places; this time I copied it from here:

include ActionController::UrlWriter
default_url_options[:host] = 'whatever'

After this you can use named route helper methods like root_path and the like.


rs = ActionController::Routing::Routes
generate :controller => 'foo', :action => 'bar'


rs.recognize_path '/'