Rails Activeadmin - custom association select box

后端 未结 1 1804
旧巷少年郎
旧巷少年郎 2021-02-01 01:54

In my Rails application, I have the following model:

class Idea < ActiveRecord::Base
  belongs_to :user
end

class User < ActiveRecord::Base
  has_many :id         


        
相关标签:
1条回答
  • 2021-02-01 02:39

    Yes, that is possible. I assume you want to use a DropDown list box for members to select a user from User model.

    form do |f|
      f.inputs do
        f.input :user_id, :label => 'Member', :as => :select, :collection => User.all.map{|u| ["#{u.last_name}, #{u.first_name}", u.id]}
        f.input :description
      end
    end
    
    0 讨论(0)
提交回复
热议问题