繁体   English   中英

如何使用f.input:object在select中添加可能性

[英]how to add possibilities in a select using f.input :object

我有一个表单,希望用户选择其中一个对象。

ActiveAdmin.register Promo do
  form do |f|
    f.inputs do
      f.input :user
    end
    f.actions
  end  
end

好的,它可以工作,但是现在我想在选择中添加“ All”的可能性,我尝试了不同的方法

f.input :user + "All"

f.input :user, as: :select, collection: [:user, "All"]

但是,当然不行

您需要在:user中获取对象集合,才能在其中注入“全部”。

@user_names = User.pluck(:name) #or whatever you want to have in your select

f.input(:user, as: :select, collection: @user_names + ['All'])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM