app/controllers/administrate/application_controller.rb in administrate-0.16.0 vs app/controllers/administrate/application_controller.rb in administrate-0.17.0

- old
+ new

@@ -4,11 +4,11 @@ def index authorize_resource(resource_class) search_term = params[:search].to_s.strip resources = Administrate::Search.new(scoped_resource, - dashboard_class, + dashboard, search_term).run resources = apply_collection_includes(resources) resources = order.apply(resources) resources = resources.page(params[:_page]).per(records_per_page) page = Administrate::Page::Collection.new(dashboard, order: order) @@ -45,11 +45,11 @@ resource = resource_class.new(resource_params) authorize_resource(resource) if resource.save redirect_to( - [namespace, resource], + after_resource_created_path(resource), notice: translate_with_resource("create.success"), ) else render :new, locals: { page: Administrate::Page::Form.new(dashboard, resource), @@ -58,11 +58,11 @@ end def update if requested_resource.update(resource_params) redirect_to( - [namespace, requested_resource], + after_resource_updated_path(requested_resource), notice: translate_with_resource("update.success"), ) else render :edit, locals: { page: Administrate::Page::Form.new(dashboard, requested_resource), @@ -74,17 +74,30 @@ if requested_resource.destroy flash[:notice] = translate_with_resource("destroy.success") else flash[:error] = requested_resource.errors.full_messages.join("<br/>") end - redirect_to action: :index + redirect_to after_resource_destroyed_path(requested_resource) end private + def after_resource_destroyed_path(_requested_resource) + { action: :index } + end + + def after_resource_created_path(requested_resource) + [namespace, requested_resource] + end + + def after_resource_updated_path(requested_resource) + [namespace, requested_resource] + end + helper_method :nav_link_state def nav_link_state(resource) - resource_name.to_s.pluralize == resource.to_s ? :active : :inactive + underscore_resource = resource.to_s.split("/").join("__") + resource_name.to_s.pluralize == underscore_resource ? :active : :inactive end helper_method :valid_action? def valid_action?(name, resource = resource_class) !!routes.detect do |controller, action|