我是新來的rails。用軌道中的關係創建幾個對象
我有一個註冊表單,用戶可以在註冊表單的同時創建一個項目。 該項目應該創建,並且新用戶成爲項目的「管理員」。
我有以下型號:
class Project < A::B
has_many :roles
has_many :users, :through => :roles
has_one :admin, :through => :roles, :conditions => "role.name = 'admin'"
has_many :members, :through => :roles, :conditions => "role.name = 'member'"
end
class User < A::B
has_many :roles
has_many :projects, :through => :roles
end
class Role < A::B
belongs_to :projects
belongs_to :users
end
我在尋找遠去的視圖中創建封裝在模型層的關係設置,並且可以很容易地創建表單,顯示錯誤等,關係中的所有對象。
希望我很清楚,新手到鐵軌。謝謝