Ruby on rails 4 如何在多对多关联中访问联接表中的参数

Ruby on rails 4 如何在多对多关联中访问联接表中的参数,ruby-on-rails-4,many-to-many,relationship,nested-attributes,Ruby On Rails 4,Many To Many,Relationship,Nested Attributes,我有两个模型,它们通过第三个模型连接到多个: class User < ActiveRecord::Base has_and_belongs_to_many :workspaces end class Workspace < ActiveRecord::Base validates :title, presence: true has_and_belongs_to_many :users end class UserWorkspace < ActiveRecor

我有两个模型,它们通过第三个模型连接到多个:

class User < ActiveRecord::Base
  has_and_belongs_to_many :workspaces
end

class Workspace < ActiveRecord::Base
  validates :title, presence: true
  has_and_belongs_to_many :users
end

class UserWorkspace < ActiveRecord::Base
  belongs_to :user
  belongs_to :workspace
  enum role: [:user, :admin]
end
class用户

不幸的是,我无法找到如何访问UserWorkspace的参数
role
。例如,
@workspace.user.last.role
不起作用。请您帮忙好吗?

您能发布错误吗?看起来是这样的:未定义的“角色”方法#