我的应用程序列出了企业活动,并允许用户使用通过回形针添加的可选照片编写有关这些活动的报告。返回存在回形针附件的相关记录
我想返回一个有附件的关联报告列表。
我的事件has_many :reports
我的报告belongs_to :event
和:
has_attached_file :photo, :styles => { :thumb => "150x150#" }, :default_url => "/images/:style/missing.png" validates_attachment_content_type :photo, :content_type => %w(image/jpeg image/jpg image/png)
我试图返回已通过这样的event_controller“秀”行动的附本人照片的所有相关报道:
@hasphoto = @event.reports.where.not(:photo => nil)
但我是得到以下错误:
Mysql2 ::错误:'where子句'中的未知列'reports.photo':SELECT'reports'。* FROM'reports'WHERE'reports.event_id = 13 AND('reports'。 'photo'is NOT NULL)
有人能告诉我我做错了什么,或者如果我以错误的方式接近这个任务,我该如何接近它?
试试'@ event.reports.photo?' – Pavan