Module: ResourceController::Helpers::Urls

Included in:
ResourceController::Helpers
Defined in:
lib/resource_controller/helpers/urls.rb

Overview

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.