app/controllers/admin/manager_controller.rb in ab_admin-0.1.2 vs app/controllers/admin/manager_controller.rb in ab_admin-0.2.0
- old
+ new
@@ -6,12 +6,57 @@
load_and_authorize_resource
helper_method :manager, :admin_partial_name
+ def custom_action
+ custom_action = manager.custom_action_for(params[:custom_action], self)
+ if custom_action.options[:method] && custom_action.options[:method] != request.method_symbol
+ raise ActionController::RoutingError.new("AbAdmin custom action for #{params[:custom_action]} not found")
+ end
+ instance_exec(&custom_action.data)
+ end
+
protected
+ def begin_of_association_chain
+ parent
+ end
+
+ def parent
+ return @parent if defined?(@parent)
+ @parent = begin
+ return if !params[:parent_resource] && !params[:parent_id]
+ assoc_name, r_id = params[:parent_resource].singularize.to_sym, params[:parent_id]
+ parent_config = manager.parent_resources.detect { |conf| conf.name == assoc_name }
+ return unless parent_config
+ assoc = resource_class.reflect_on_association(parent_config.name)
+ return unless assoc
+ assoc.klass.find(r_id)
+ end
+ end
+
+ def parent?
+ !!parent
+ end
+
+ def parent_type
+ parent.class.name.underscore.to_sym
+ end
+
+ def parent_class
+ parent.class
+ end
+
+ def parent_path
+ "/admin/#{parent_class.model_name.plural}/#{parent.id}"
+ end
+
+ def parent_collection_path
+ "/admin/#{parent_class.model_name.plural}"
+ end
+
def tree_node_renderer
manager.tree_node_renderer || super
end
def resource_action_items
@@ -47,20 +92,20 @@
manager_instance = "AbAdmin#{resource_class.name}".constantize.instance
unless manager_instance.allow_action?(action_name)
raise ActionController::RoutingError.new("AbAdmin action #{action_name} for #{resource_class.name} not found")
end
manager_instance
- #rescue NameError
- # raise ActionController::RoutingError.new("AbAdmin manager_model for #{resource_class.name} not found")
+ rescue NameError => e
+ raise ActionController::RoutingError.new("AbAdmin manager_model for #{resource_class.name} not found (#{e.message})")
end
end
def resource_class
@model ||= begin
params[:model_name].singularize.classify.constantize
- rescue NameError
- raise ActionController::RoutingError.new("AbAdmin model #{params[:model_name]} not found")
+ rescue NameError => e
+ raise ActionController::RoutingError.new("AbAdmin model #{params[:model_name]} not found (#{e.message})")
end
end
def preview_resource_path(item)
return unless manager.preview_path
@@ -96,15 +141,15 @@
admin_new_path(options.merge(:model_name => resource_collection_name))
end
def edit_resource_path(record=nil, options={})
record ||= resource
- admin_edit_path(options.merge(:model_name => resource_collection_name, :id => record.id))
+ admin_edit_path(options.merge(:model_name => record.class.model_name.plural, :id => record.id))
end
def resource_path(record=nil, options={})
record ||= resource
- admin_show_path(options.merge(:model_name => resource_collection_name, :id => record.id))
+ admin_show_path(options.merge(:model_name => record.class.model_name.plural, :id => record.id))
end
def self.cancan_resource_class
AbAdmin::Controllers::CanCanManagerResource
end