app/controllers/avo/actions_controller.rb in avo-2.5.2.pre.7 vs app/controllers/avo/actions_controller.rb in avo-2.6.0

- old
+ new

@@ -12,18 +12,16 @@ def handle resource_ids = action_params[:fields][:resource_ids].split(",") models = @resource.class.find_scope.find resource_ids - fields = action_params[:fields].select do |key, value| - key != "resource_ids" - end + fields = action_params[:fields].except("resource_ids") args = { fields: fields, current_user: _current_user, - resource: resource, + resource: resource } args[:models] = models unless @action.standalone performed_action = @action.handle_action(**args) @@ -47,30 +45,47 @@ @action = action_class.new(model: model, resource: resource, user: _current_user) end def respond(response) response[:type] ||= :reload - response[:message_type] ||= :notice - response[:message] ||= I18n.t("avo.action_ran_successfully") + messages = get_messages response if response[:type] == :download return send_data response[:path], filename: response[:filename] end respond_to do |format| format.html do + # Flash the messages collected from the action + messages.each do |message| + flash[message[:type]] = message[:body] + end + if response[:type] == :redirect path = response[:path] if path.respond_to? :call path = instance_eval(&path) end - redirect_to path, "#{response[:message_type]}": response[:message] + redirect_to path elsif response[:type] == :reload - redirect_back fallback_location: resources_path(resource: @resource), "#{response[:message_type]}": response[:message] + redirect_back fallback_location: resources_path(resource: @resource) end end end + end + + private + + def get_messages(response) + default_message = { + type: :info, + body: I18n.t("avo.action_ran_successfully") + } + + return [default_message] if response[:messages].blank? + + response[:messages] end end end