【发布时间】:2011-10-23 11:52:31
【问题描述】:
我是 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
我正在寻找创建封装模型层中的关系设置,并使其易于在视图中为关系中的所有对象创建表单、显示错误等。
希望我很清楚,rails 新手。谢谢
【问题讨论】:
标签: ruby-on-rails ruby activerecord activemodel