|
|
# Overwriting the resource module to setup only the routes that we want to use.
# we also append the .:format value where necessary
module ActionController
module Resources
private
# Handled setting up the action for :collection => { } actions.
def map_collection_actions(map, resource)
resource.collection_methods.each do |method, actions|
actions.each do |action|
action_options = action_options_for(action, resource, method)
map.named_route("#{action}_#{resource.name_prefix}#{resource.plural}", "#{resource.path}#{resource.action_separator}#{action}.:format", action_options)
# this is the ;action route (ie: /widgets/1;featured). I don't like it, so I've commented it out.
# the new alternative is /widgets/1/featured which I prefer. It's defined on the line right above this
# map.connect("#{resource.path};#{action}.:format", action_options)
end
end
end
def map_default_collection_actions(map, resource)
# index route. /widgets.:format
map.named_route("#{resource.name_prefix}#{resource.plural}", "#{resource.path}.:format", action_options_for("index", resource))
# create route. we don't bother with .:format because it's never displayed to the client
map.connect(resource.path, action_options_for("create", resource))
end
# create the default routes for a singleton.
def map_default_singleton_actions(map, resource)
# we don't bother with .:format because it's never displayed to the client
map.connect(resource.path, action_options_for("create", resource))
end
# Handled setting up the action for :new => { } actions. 'new' is a default new action
def map_new_actions(map, resource)
resource.new_methods.each do |method, actions|
actions.each do |action|
action_options = action_options_for(action, resource, method)
if action == :new
# setup the basic 'new' route. ie: new_widget => /widgets/new.:format
map.named_route("new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}.:format", action_options)
else
map.named_route("#{action}_new_#{resource.name_prefix}#{resource.singular}", "#{resource.new_path}#{resource.action_separator}#{action}.:format", action_options)
# this is the ;action route (ie: /widgets/1;edit). I don't like it, so I've commented it out.
# the new alternative is /widgets/1/edit which I prefer. It's defined on the line right above this
# map.connect("#{resource.new_path};#{action}", action_options)
end
end
end
end
# Handled setting up the action for :member => { } actions. 'edit' is a default member action
def map_member_actions(map, resource)
resource.member_methods.each do |method, actions|
actions.each do |action|
# setup the additional member action routes. ie: edit_widget => /widget/:id/edit
map.named_route(
"#{action}_#{resource.name_prefix}#{resource.singular}",
"#{resource.member_path}#{resource.action_separator}#{action}.:format",
action_options_for(action, resource, method)
)
end
end
# setup the singular named route. ie: widget
# this ends up being widget_path(widget) => /widget/:id.:format
map.named_route("#{resource.name_prefix}#{resource.singular}", "#{resource.member_path}.:format", action_options_for("show", resource))
# Update and delete aren't setup as named routes because they would collide
# Here we just setup standard routes for the update and destroy methods
# we don't bother with .:format on update and delete because they are never shown in the browser
map.connect(resource.member_path, action_options_for("update", resource))
map.connect(resource.member_path, action_options_for("destroy", resource))
end
end
end
|