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

时间:2014-10-08 10:43:28

标签: ruby-on-rails select input collections

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

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"]

但当然,它不起作用

1 个答案:

答案 0 :(得分:0)

你需要获取对象的集合:用户注入'全部'在它。

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

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