lib/active_admin/router.rb in andrewroth_activeadmin-0.3.4 vs lib/active_admin/router.rb in andrewroth_activeadmin-0.3.4.1
- old
+ new
@@ -26,31 +26,37 @@
end
end
# Now define the routes for each resource
router.instance_exec(@application.namespaces) do |namespaces|
- resources = namespaces.values.collect{|n| n.resources.values }.flatten
+ resources = namespaces.values.collect{|n| n.resources.resources }.flatten
resources.each do |config|
# Define the block the will get eval'd within the namespace
route_definition_block = Proc.new do
- resources config.underscored_resource_name.pluralize do
-
- # Define any member actions
- member do
- config.member_actions.each do |action|
- # eg: get :comment
- send(action.http_verb, action.name)
+ case config
+ when Resource
+ resources config.underscored_resource_name.pluralize do
+ # Define any member actions
+ member do
+ config.member_actions.each do |action|
+ # eg: get :comment
+ send(action.http_verb, action.name)
+ end
end
- end
- # Define any collection actions
- collection do
- config.collection_actions.each do |action|
- send(action.http_verb, action.name)
+ # Define any collection actions
+ collection do
+ config.collection_actions.each do |action|
+ send(action.http_verb, action.name)
+ end
end
end
+ when Page
+ match "/#{config.underscored_resource_name}" => "#{config.underscored_resource_name}#index"
+ else
+ raise "Unsupported config class: #{config.class}"
end
end
# Add in the parent if it exists
if config.belongs_to?
@@ -58,10 +64,11 @@
route_definition_block = Proc.new do
# If its optional, make the normal resource routes
instance_eval &routes_for_belongs_to if config.belongs_to_config.optional?
# Make the nested belongs_to routes
- resources config.belongs_to_config.target.underscored_resource_name.pluralize do
+ # :only is set to nothing so that we don't clobber any existing routes on the resource
+ resources config.belongs_to_config.target.underscored_resource_name.pluralize, :only => [] do
instance_eval &routes_for_belongs_to
end
end
end