class CmAdmin::ResourceController
def cm_custom_method(params)
def cm_custom_method(params) records = "CmAdmin::#{@model.name}Policy::Scope".constantize.new(Current.user, @model.name.constantize).resolve @current_action = @action if @action.parent == 'index' records = apply_scopes(records) @ar_object = filter_by(params, records, @model.filter_params(params)) else resource_identifier end respond_to do |format| if @action.action_type == :custom if @action.child_records if request.xhr? format.html { render partial: '/cm_admin/main/associated_table' } else format.html { render @action.layout } end elsif @action.display_type == :page data = @action.parent == "index" ? @ar_object.data : @ar_object format.html { render @action.partial } else begin response_object = @action.code_block.call(@response_object) if response_object.class == Hash format.json { render json: response_object } elsif response_object.errors.empty? redirect_url = @model.current_action.redirection_url || @action.redirection_url || request.referrer || "/cm_admin/#{@model.ar_model.table_name}/#{@response_object.id}" format.html { redirect_to redirect_url, notice: "#{@action.name.titleize} is successful" } else error_messages = response_object.errors.full_messages.map{|error_message| "<li>#{error_message}</li>"}.join format.html { redirect_to request.referrer, alert: "<b>#{@action.name.titleize} is unsuccessful</b><br /><ul>#{error_messages}</ul>" } end rescue => exception format.html { redirect_to request.referrer, alert: "<b>#{@action.name.titleize} is unsuccessful</b><br /><p>#{exception.message}</p>" } end end end end end