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.
You can show them with rake routes
directly.
In a Rails console, you can call app.post_path
. This will work in Rails ~= 2.3 and >= 3.1.0.
you can also
include Rails.application.routes.url_helpers
from inside a console sessions to access the helpers:
url_for controller: :users, only_path: true users_path # => '/users'
or
Rails.application.routes.url_helpers.users_path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With