【问题标题】:Rails Admin - message before updateRails 管理员 - 更新前的消息
【发布时间】:2016-08-20 00:26:52
【问题描述】:

我使用 rails_admin。

有人知道我如何在更新之前显示确认消息(带有操作)吗?

【问题讨论】:

    标签: ruby-on-rails-4 rails-admin


    【解决方案1】:

    我会创建一个自定义操作或覆盖现有的操作。像这样的:

    class Update2
      RailsAdmin::Config::Actions.register(self)
      register_instance_option :visible? do
        # 
      end
      register_instance_option :link_icon do
        # your icon here
      end
      register_instance_option :http_methods do
        [:get, :post]
      end
      register_instance_option :controller do
        Proc.new do
          if request.post?
            @object.update
            flash[:notice] = "Updated #{@object.name}."
            redirect_to show_path
          end
        end
      end
    end
    

    然后创建一个页面app/views/rails_admin/main/update2.html.haml

    %h3 
      = "Are you sure you want to update '#{@object.name}'
    = link_to 'Update', update2_path, method: 'post', class: "btn btn-danger"
    = link_to 'Cancel', show_path, class: "btn btn-primary"
    

    当您单击 Update2 时,您将通过 GET 转到该页面。然后在 POST 上它实际上会更新。

    【讨论】:

    • 谢谢,可以解决。
    猜你喜欢
    • 2019-01-26
    • 2021-12-05
    • 1970-01-01
    • 2012-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-21
    • 2020-01-10
    相关资源
    最近更新 更多