【发布时间】:2013-12-14 03:29:17
【问题描述】:
如何在 Pin 模型视图中使用其 ID 访问 Image.photo?
目前我正在这样做,如果我删除 image_tag 或银行图像空间,它会给我随机数。
<td><%= image_tag Image.find_by_id(pin.pic) %></td>
这个给了我未定义的方法 `photo' for nil:NilClass
<td><%= image_tag Image.find_by_id(pin.pic).photo.url(:small) %></td>
class Pin < ActiveRecord::Base
attr_accessible :board, :pic, :pin_time, :user, :apic, :photo
belongs_to :auser, :class_name => 'User', :foreign_key => 'user'
belongs_to :apic, :class_name => 'Image',:foreign_key => 'pic'
end
class Image < ActiveRecord::Base
attr_accessible :description, :uid, :web_url, :photo, :photo_file_name,:photo_content_type, :photo_file_size, :photo_updated_at, :id
has_attached_file :photo, :styles => { :small => "150x150>", :medium => "300x300", :large => "600x600"}
belongs_to :user
validates_attachment_presence :photo
validates_attachment_size :photo, :less_than => 5.megabytes
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png']
end
【问题讨论】:
-
您是否尝试过使用以下内容登录您的 s3 帐户:addons.mozilla.org/en-US/firefox/addon/amazon-s3-organizers3fox 并检查文件是否存在?
-
它没有加载到亚马逊。它在本地加载它,是的,文件确实存在。
标签: ruby-on-rails ruby-on-rails-3 view model paperclip