我工作的一個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