我工作的一个ActiveAdmin应用这个模型:ActiveAdmin自定义视图的has_many:通过
用户
class User < ActiveRecord::Base
# A User has many roles for interact on a project
has_many :roles, :dependent => :destroy
has_many :projects, :through => :role
end
角色
class Role < ActiveRecord::Base
belongs_to :user
belongs_to :project
end
项目
class Project < ActiveRecord::Base
# A project has many roles for interact
has_many :roles, :dependent => :destroy
has_many :users, :through => :role
accepts_nested_attributes_for :roles
end
要在每个项目中的角色添加用户我使这种形式:
form do |f|
f.inputs "Details" do # Project's fields
f.input :title
f.input :code
end
f.has_many :roles do |app_f|
app_f.inputs do
if !app_f.object.nil?
app_f.input :_destroy, :as => :boolean, :label => "Destroy?"
end
app_f.input :user
app_f.input :senior_author
end
end
f.buttons
end
我的第一个问题是,我怎样才能使一个与user.firstname + user.lastname。其实我有这样的事情:
#<User:0x007fb98a7d6568>
第二个问题是我的榜样是布尔属性的列表:
:senior_author
:first_author
:viewer
....
我可以带吗?
我已经回答了这个问题:) – Awea 2012-04-15 17:29:23