0
用户可以有许多教育,并且教育可以有很多用户。Rails 5:如何通过连接表访问属性
class User < ApplicationRecord
has_many :users_eds, dependent: :destroy
has_many :educations, through: :users_eds, dependent: :destroy
class Education < ApplicationRecord
has_many :users_eds, dependent: :destroy
has_many :users, through: :users_eds
class UsersEd < ApplicationRecord
belongs_to :user
belongs_to :education
在我的用户列表索引视图,我想告诉每个用户的最新education.level,所以我写:
- @users.each do |user|
= user.username
= user.educations.last
然而,这种输出
#<Education:0x007fec96d2bdf8>
什么访问education.level或其任何属性的正确语法是什么?
当我写= user.educations.last.level,我得到的错误:未定义的方法'水平'为零:NilClass –