| Module | InheritedResources::UrlHelpers |
| In: |
lib/inherited_resources/url_helpers.rb
|
When you use InheritedResources it creates some UrlHelpers for you. And they handle everything for you.
# /posts/1/comments
resource_url # => /posts/1/comments/#{@comment.to_param}
resource_url(comment) # => /posts/1/comments/#{comment.to_param}
new_resource_url # => /posts/1/comments/new
edit_resource_url # => /posts/1/comments/#{@comment.to_param}/edit
collection_url # => /posts/1/comments
parent_url # => /posts/1
# /projects/1/tasks
resource_url # => /projects/1/tasks/#{@task.to_param}
resource_url(task) # => /projects/1/tasks/#{task.to_param}
new_resource_url # => /projects/1/tasks/new
edit_resource_url # => /projects/1/tasks/#{@task.to_param}/edit
collection_url # => /projects/1/tasks
parent_url # => /projects/1
# /users
resource_url # => /users/#{@user.to_param}
resource_url(user) # => /users/#{user.to_param}
new_resource_url # => /users/new
edit_resource_url # => /users/#{@user.to_param}/edit
collection_url # => /users
parent_url # => /
The nice thing is that those urls are not guessed during runtime. They are all created when you inherit.
This method hard code url helpers in the class.
We are doing this because is cheaper than guessing them when our action is being processed (and even more cheaper when we are using nested resources).
When we are using polymorphic associations, those helpers rely on polymorphic_url Rails helper.