未定义的方法`image'如果连接表

时间:2016-12-05 15:18:42

标签: ruby-on-rails paperclip

class Photo < ApplicationRecord
 has_many :user_comments
 has_many :users, through: :user_comments
 has_attached_file :image
 validates_attachment_content_type :image, content_type: /\Aimage/.*\z/
end

class User < ApplicationRecord
 has_many :user_comments
 has_many :photos, through: :user_comments
end

class UserComment < ApplicationRecord
 belongs_to :photo
 belongs_to :user
end

执行[union = UserComment.joins(:user,:photo).where('photos.id =?',1).first] - 确定

执行[union.image] - 错误 NoMethodError:#UserComment的未定义方法`image':0x007fe8845fbf58

如何解决?

0 个答案:

没有答案