app/controllers/admin/manager_controller.rb in ab_admin-0.2.3 vs app/controllers/admin/manager_controller.rb in ab_admin-0.3.0
- old
+ new
@@ -23,12 +23,12 @@
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]
+ return if !params[:parent_resource] && !params[:parent_resource_id]
+ assoc_name, r_id = params[:parent_resource].singularize.to_sym, params[:parent_resource_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)
@@ -62,15 +62,16 @@
def resource_action_items
manager.resource_action_items
end
def action_items
- manager.default_action_items_for(action_name.to_sym, params[:id].present?) + manager.action_items_for(action_name.to_sym)
+ for_resource = params[:id].present? && resource.persisted?
+ manager.default_action_items_for(action_name.to_sym, for_resource) + manager.action_items_for(action_name.to_sym)
end
def apply_batch_action(item, batch_action)
- call_method_or_proc_on item, manager.batch_action_list.detect{|a| a.name == batch_action }.data, :exec => false
+ call_method_or_proc_on item, manager.batch_action_list.detect{|a| a.name == batch_action }.data, exec: false
end
def allow_batch_action?(batch_action)
manager.batch_action_list.detect { |a| a.name == batch_action }
end
@@ -99,11 +100,11 @@
end
end
def resource_class
@model ||= begin
- params[:model_name].singularize.classify.constantize
+ params[:model_name].classify.constantize
rescue NameError => e
raise ActionController::RoutingError.new("AbAdmin model #{params[:model_name]} not found (#{e.message})")
end
end
@@ -128,28 +129,28 @@
def resource_instance_name
resource_class.model_name.singular
end
def collection_path(options={})
- admin_index_path(options.merge(:model_name => resource_collection_name))
+ admin_index_path(options.merge(model_name: resource_collection_name))
end
def collection_url(options={})
- admin_index_url(options.merge(:model_name => resource_collection_name))
+ admin_index_url(options.merge(model_name: resource_collection_name))
end
def new_resource_path(options={})
- admin_new_path(options.merge(:model_name => resource_collection_name))
+ 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 => record.class.model_name.plural, :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 => record.class.model_name.plural, :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