# frozen_string_literal: true module Maquina module Update extend ActiveSupport::Concern included do def update(&block) @resource ||= begin scope = resource_class.all scope = authorized_scope(scope) if policy_class.present? resource = scope.find_by!(find_by_param => params[:id]) authorize! resource, with: policy_class if policy_class.present? resource end saved = @resource.update(resource_secure_params) status = saved ? :accepted : :unprocessable_entity response.status = status set_flash_message(status) dual_action_response(@resource, &block) end alias_method :update!, :update end end end