代码之家  ›  专栏  ›  技术社区  ›  Alan

ActiveAdmin中的自定义按钮

  •  0
  • Alan  · 技术社区  · 7 年前

    请注意,“MyThingy”不在数据库中,而是使用API中的数据进行计算。 enter image description here

    我想为该字段添加一个筛选器。我想寄这个 abc 将文本作为参数添加到我所在的同一编辑操作中。

    enter image description here

    我的表单如下所示:

    form do |f|
      f.inputs "Details" do
        f.input :my_thingy,
          label: 'My thingy',
          as: :select,
          collection: my_thingys,
        f.input :my_thingy_filter, label: "Filter My thingy by..."
        f.button :filter
      end
      f.actions
    end
    

    我想让这个按钮重定向到同一个页面,值为 my_thingy_filter

    我该怎么做?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Alan    7 年前

    member_action :

    member_action :thingy_filter, method: :patch do
      redirect_to edit_thingy_path(resource, thingy_filter: params["thingy"]["thingy_filter"])
    end
    

    及 formaction 按下按钮:

    form do |f|
      f.inputs "Details" do
        f.input :my_thingy,
          label: 'My thingy',
          as: :select,
          collection: my_thingys,
        f.input :my_thingy_filter, label: "Filter My thingy by..."
        f.button "Filter", formaction: "thingy_filter"
      end
      f.actions
    end
    

    无论如何,通过添加 a better select