app/controllers/administrate/application_controller.rb in administrate-0.20.1 vs app/controllers/administrate/application_controller.rb in administrate-1.0.0.beta1
- old
+ new
@@ -13,31 +13,31 @@
render locals: {
resources: resources,
search_term: search_term,
page: page,
- show_search_bar: show_search_bar?,
+ show_search_bar: show_search_bar?
}
end
def show
render locals: {
- page: Administrate::Page::Show.new(dashboard, requested_resource),
+ page: Administrate::Page::Show.new(dashboard, requested_resource)
}
end
def new
resource = new_resource
authorize_resource(resource)
render locals: {
- page: Administrate::Page::Form.new(dashboard, resource),
+ page: Administrate::Page::Form.new(dashboard, resource)
}
end
def edit
render locals: {
- page: Administrate::Page::Form.new(dashboard, requested_resource),
+ page: Administrate::Page::Form.new(dashboard, requested_resource)
}
end
def create
resource = new_resource(resource_params)
@@ -45,28 +45,28 @@
if resource.save
yield(resource) if block_given?
redirect_to(
after_resource_created_path(resource),
- notice: translate_with_resource("create.success"),
+ notice: translate_with_resource("create.success")
)
else
render :new, locals: {
- page: Administrate::Page::Form.new(dashboard, resource),
+ page: Administrate::Page::Form.new(dashboard, resource)
}, status: :unprocessable_entity
end
end
def update
if requested_resource.update(resource_params)
redirect_to(
after_resource_updated_path(requested_resource),
- notice: translate_with_resource("update.success"),
+ notice: translate_with_resource("update.success")
)
else
render :edit, locals: {
- page: Administrate::Page::Form.new(dashboard, requested_resource),
+ page: Administrate::Page::Form.new(dashboard, requested_resource)
}, status: :unprocessable_entity
end
end
def destroy
@@ -82,16 +82,16 @@
def filter_resources(resources, search_term:)
Administrate::Search.new(
resources,
dashboard,
- search_term,
+ search_term
).run
end
def after_resource_destroyed_path(_requested_resource)
- { action: :index }
+ {action: :index}
end
def after_resource_created_path(requested_resource)
[namespace, requested_resource]
end
@@ -101,11 +101,11 @@
end
helper_method :nav_link_state
def nav_link_state(resource)
underscore_resource = resource.to_s.split("/").join("__")
- resource_name.to_s.pluralize == underscore_resource ? :active : :inactive
+ (resource_name.to_s.pluralize == underscore_resource) ? :active : :inactive
end
# Whether the named action route exists for the resource class.
#
# @param resource [Class, String, Symbol] A class of resources, or the name
@@ -139,12 +139,12 @@
def order
@order ||= Administrate::Order.new(
sorting_attribute,
sorting_direction,
association_attribute: order_by_field(
- dashboard_attribute(sorting_attribute),
- ),
+ dashboard_attribute(sorting_attribute)
+ )
)
end
def order_by_field(dashboard)
return unless dashboard.try(:options)
@@ -199,13 +199,13 @@
return relation if resource_includes.empty?
relation.includes(*resource_includes)
end
def resource_params
- params.require(resource_class.model_name.param_key).
- permit(dashboard.permitted_attributes(action_name)).
- transform_values { |v| read_param_value(v) }
+ params.require(resource_class.model_name.param_key)
+ .permit(dashboard.permitted_attributes(action_name))
+ .transform_values { |v| read_param_value(v) }
end
def read_param_value(data)
if data.is_a?(ActionController::Parameters) && data[:type]
if data[:type] == Administrate::Field::Polymorphic.to_s
@@ -234,17 +234,17 @@
end
def translate_with_resource(key)
t(
"administrate.controller.#{key}",
- resource: resource_resolver.resource_title,
+ resource: resource_resolver.resource_title
)
end
def show_search_bar?
dashboard.attribute_types_for(
- dashboard.all_attributes,
+ dashboard.all_attributes
).any? { |_name, attribute| attribute.searchable? }
end
# Whether the current user is authorized to perform the named action on the
# resource.
@@ -277,10 +277,10 @@
if authorized_action?(resource, action_name)
resource
else
raise Administrate::NotAuthorizedError.new(
action: action_name,
- resource: resource,
+ resource: resource
)
end
end
def paginate_resources(resources)