Rails Activeadmin-自定义关联选择框 [英] Rails Activeadmin - custom association select box
本文介绍了Rails Activeadmin-自定义关联选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Rails应用程序中,我有以下模型:
In my Rails application, I have the following model:
class Idea < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :ideas
end
我正在创建 Idea 模型的href = http://www.activeadmin.info/> ActiveAdmin CRUD,其自定义形式类似于
I am creating ActiveAdmin CRUD for my Idea
model with the custom form that looks something like that looks something like that:
form do |f|
f.inputs do
f.input :member
f.input :description
end
end
要求是拥有成员关联内容的自定义文本,即#{last_name},#{first_name}
。
The requirement is to have the custom text for a content of the member association, i.e "#{last_name}, #{first_name}"
. Is it possible to customize my member select box to achieve it?
任何帮助将不胜感激。
推荐答案
是的,这是可能的。我假设您想使用成员
的下拉列表框从 User
模型中选择一个用户。
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
这篇关于Rails Activeadmin-自定义关联选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文