-1
このような質問があります。ユーザー、プロジェクト、接続::多対多のアソシエーションのアトリビュートへのアクセス方法
class User < ActiveRecord::Base
has_many :connections
has_many :tasks, :through => :connections
end
class Project < ActiveRecord::Base
has-many :connections
has_many :users, :through => :connections
end
class Connection < ActiveRecord::Base
belongs_to :user
belongs_to :project
enum status: [:manager, :developer]
end
質問がされています。どのように私はモデル接続の「状態」属性にアクセスすることができます例えば、私は3つのモデルがありますか? には、例えば、私はプロジェクトを取る:
@project = Projects.last
、私はこのプロジェクトからユーザを取得するだけでなく、私は彼らがプロジェクトで果たす役割に興味を持っています:もちろん
@project.users.each do |u|
u.name
u.connection.role #Here I get an error `undefined method `connection'`
end
u.roleそのような属性「ロール」がユーザに存在しないので、動作しないであろう。 属性 "ロール"を表示して編集したいと思っています どのような考えですか?