Rails Admin:自定义提交按钮类型

时间:2019-05-20 15:40:39

标签: rails-admin

问题:

我可以有一个自定义的提交按钮类型,就像Rails管理员默认使用的现有“保存并添加另一个”按钮和“保存并编辑”按钮一样吗?

详细信息:

因此,我想出了如何通过在/ app / views / rails_admin / main内部明确定义_submit_buttons.html.haml来自定义提交按钮的方法

.form-group.form-actions
  .col-sm-offset-2.col-sm-10
    %input{type: :hidden, name: 'return_to', value: (params[:return_to].presence || request.referer)}
    %button.btn.btn-primary{type: "submit", name: "_save", :'data-disable-with' => t("admin.form.save")}
      %i.icon-white.icon-ok
      = t("admin.form.save")
    %span.extra_buttons
      - if (authorized? :copy, @abstract_model) #this adds a new field called copy if you click this. its not a full new action
        %button.btn.btn-info{type: "submit", name: "_copy", :'data-disable-with' => t("admin.form.copy")}
          = t("Save and Copy")
      - if authorized? :new, @abstract_model
        %button.btn.btn-info{type: "submit", name: "_add_another", :'data-disable-with' => t("admin.form.save_and_add_another")}
          = t("admin.form.save_and_add_another")
      - if authorized? :edit, @abstract_model
        %button.btn.btn-info{type: "submit", name: "_add_edit", :'data-disable-with' => t("admin.form.save_and_edit")}
          = t("admin.form.save_and_edit")
      %button.btn.btn-default{type: "submit", name: "_continue", :'data-disable-with' => t("admin.form.cancel"), :formnovalidate => true}
        %i.icon-remove
        = t("admin.form.cancel")

但是,我添加的“保存并复制”按钮显然不起作用。我看到,尽管有一个名为“复制”的动作,但它(以及其他额外的保存按钮)的作用是像平常一样调用new或edit,但是有一个名为_copy(或_add_another或_add_edit等)的额外字段。

如果我能使控制器在将副本传递给它时表现出不同的行为,那就太好了,这正是我所需要的。但是,该控制器是默认的Rails Admin MainController,我在该主题上阅读的所有内容都让我相信它是完全不变的。

0 个答案:

没有答案