我有一些使用Photo多态模型的模型。通过控制台或检查或记录器保存或访问照片属性一切都很好,但如果我尝试直接在视图中调用它们,例如@banner.photo.file
,它会返回undefined method 'file' etc for nil:Nil
通过回形针上传照片,所有模型都设置为has_one :photo, :as => :imageable
和accepts_nested_attributes_for :photo, :allow_destroy => true
。照片模型设置为belongs_to :imageable, :polymorphic => true
和has_attached_file :file
。
这些是Photo模型的列:
id:integer
file:string
imageable_id:integer
imageable_type:string
file_file_name:string
file_content_type:string
file_file_size:integer
(除了created_at等)
在我看来:
<% @banners.each do |b| %>
<%= b.inspect %><br />
<%= b.photo.inspect %><br /><br />
<% end %>
您可以在http://bdyvu2.hospedagemweb.net/
看到检查非常感谢提前!!