在rails console里测试routes

Sometimes you need to check what your route helpers are returning, and the "rake routes" task isn't enough. Those helpers are accessible through an instance of the ActionController::Integration::Session class, and at the Rails console there is one instance of this class already available:


>> app.class
=> ActionController::Integration::Session
>> app.users_path
=> "/users"
Inside the app object, the host name is automatically prepopulated to "www.example.com":

view sourceprint?
>> app.host
=> "www.example.com"
>> app.users_url
=> "http://www.example.com/users"
You can change that host name easily:

>> app.host = "evolve.st"
=> "evolve.st"
>> app.users_url
=> "http://evolve.st/users"
And remember: That Session instance can be used to simulate HTTP requests too. If you still didn't know about it, you should take a look at its Rails documentation page, because you will find it really interesting.

你可能感兴趣的:(Rails,route)