回形针 - 无法获取任何上传的图像
Paperclip - Can't get to any uploaded image
我已经设法使回形针工作并上传了我的图像,但是由于未知原因,Rails即使我能找到它们也找不到。
我使用的是 Windows 10 + Rubymine 2016.1,在 arborescence 的项目中,我可以看到几个文件夹被 Rubymine 标记为红色。这些文件夹包含我上传的图片,但是当我尝试通过浏览器或执行 <%= image_tag(@post.image.url(:small)) %>
访问它们时,我得到 404 状态
这是我的模型
class Post < ActiveRecord::Base
validates_presence_of(:titre, :contenu)
has_attached_file :image, :styles => {
:large => "400x400>",
:medium => "300x300>",
:thumb => "100x100#"
},
:default_url => "/images/:style/missing.png",
:path => ":rails_root/public/system/:class/:attachment/:style/:filename",
:url => '/images/:class/:id/:basename.:extension'
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end
有谁知道颜色的含义,或者如何修复我的 404 错误状态?
提前致谢
更新
在尝试一些徒劳的事情时,我在 brut HTML 中手动添加了以下内容:
<img src="/system/posts/images/large/sorry.jpg" alt="">
并且我的图像显示得很好。所以我猜 @post.image.url 创建的路径是错误的,因为它是 /system/posts/images/000/000/012/medium/nope.jpg
我怎样才能把它放在我的模型中?
没有为图像声明 :small
标识符。尝试:
<%= image_tag(@post.image.url(:thumb)) %>
:path => "#{Rails.root}/public/system/:class/:attachment/:style/:filename"
此外,我认为没有必要在模型附件配置中添加 :url
。
对我来说工作得很好:
has_attached_file :image,
:styles => {
:thumb => "100x100#",
:small => "300x300>",
:large => "700x700>"
},
:path => "image/:class/:style/:id.:extension"
我已经设法使回形针工作并上传了我的图像,但是由于未知原因,Rails即使我能找到它们也找不到。
我使用的是 Windows 10 + Rubymine 2016.1,在 arborescence 的项目中,我可以看到几个文件夹被 Rubymine 标记为红色。这些文件夹包含我上传的图片,但是当我尝试通过浏览器或执行 <%= image_tag(@post.image.url(:small)) %>
访问它们时,我得到 404 状态
这是我的模型
class Post < ActiveRecord::Base
validates_presence_of(:titre, :contenu)
has_attached_file :image, :styles => {
:large => "400x400>",
:medium => "300x300>",
:thumb => "100x100#"
},
:default_url => "/images/:style/missing.png",
:path => ":rails_root/public/system/:class/:attachment/:style/:filename",
:url => '/images/:class/:id/:basename.:extension'
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
end
有谁知道颜色的含义,或者如何修复我的 404 错误状态? 提前致谢
更新
在尝试一些徒劳的事情时,我在 brut HTML 中手动添加了以下内容:
<img src="/system/posts/images/large/sorry.jpg" alt="">
并且我的图像显示得很好。所以我猜 @post.image.url 创建的路径是错误的,因为它是 /system/posts/images/000/000/012/medium/nope.jpg
我怎样才能把它放在我的模型中?
没有为图像声明 :small
标识符。尝试:
<%= image_tag(@post.image.url(:thumb)) %>
:path => "#{Rails.root}/public/system/:class/:attachment/:style/:filename"
此外,我认为没有必要在模型附件配置中添加 :url
。
对我来说工作得很好:
has_attached_file :image,
:styles => {
:thumb => "100x100#",
:small => "300x300>",
:large => "700x700>"
},
:path => "image/:class/:style/:id.:extension"