views:

78

answers:

1

Rails defines a bunch of magic with named routes that make helpers for your routes. Sometimes, especially with nested routes, it can get a little confusing to keep track of what URL you'll get for a given route helper method call. Is it possible to, using the Ruby console, see what link a given helper function will generate? For example, given a named helper like post_path(post) I want to see what URL is generated.

+2  A: 

You can show them with rake routes directly.

In a Rails console, you can call app.post_path. This doesn't work in Rails 3, though.

Chubas
Just in a follow up of my own comment, seems this is possible from rails 3 console, in case you're using.First, stick a fake request into your app object, by calling something like`app.get "/"`then just instance_eval the wanted methods, as they are now protected by default. Something like:`app.instance_eval{ post_path(post) }`
Chubas