| Path: | lib/resource_controller/helpers/urls.rb |
| Last Update: | Thu Dec 22 23:39:50 +0000 2016 |
Thanks to Urligence, you get some free url helpers.
No matter what your controller looks like…
[edit_|new_]object_url # is the equivalent of saying [edit_|new_]post_url(@post) [edit_|new_]object_url(some_other_object) # allows you to specify an object, but still maintain any paths or namespaces that are present collection_url # is like saying posts_url
Url helpers are especially useful when working with polymorphic controllers.
# /posts/1/comments
object_url #=> /posts/1/comments/#{@comment.to_param}
object_url(comment) #=> /posts/1/comments/#{comment.to_param}
edit_object_url #=> /posts/1/comments/#{@comment.to_param}/edit
collection_url #=> /posts/1/comments
# /products/1/comments
object_url #=> /products/1/comments/#{@comment.to_param}
object_url(comment) #=> /products/1/comments/#{comment.to_param}
edit_object_url #=> /products/1/comments/#{@comment.to_param}/edit
collection_url #=> /products/1/comments
# /comments
object_url #=> /comments/#{@comment.to_param}
object_url(comment) #=> /comments/#{comment.to_param}
edit_object_url #=> /comments/#{@comment.to_param}/edit
collection_url #=> /comments
Or with namespaced, nested controllers…
# /admin/products/1/options
object_url #=> /admin/products/1/options/#{@option.to_param}
object_url(option) #=> /admin/products/1/options/#{option.to_param}
edit_object_url #=> /admin/products/1/options/#{@option.to_param}/edit
collection_url #=> /admin/products/1/options
You get the idea. Everything is automagical! All parameters are inferred.