使用rails 3.1时设置默认URL?
我认为新的资产管道搞乱了 CarrierWave 默认方法。我想用作默认图像的文件存储为 app/assets/images/listing_defaults/default.png
。
在我的上传器中,我有以下内容
def default_url
"assets/listing_defaults/" + [version_name, "default.png"].compact.join('_')
end
当我运行我的应用程序时,可以在该地址浏览图像 (localhost:3000/assets/listing_defaults/default.png
)
但出于某种原因,当我尝试让默认图像显示在我的视图中,我什么也没得到。
<p>
<b>Images:</b>
<ul>
<% @listing.images.each do |image| -%>
<li><%= image_tag image.image_url.to_s %></li>
<% end -%>
</ul>
</p>
然而上传的文件似乎工作正常。有什么想法吗?
顺便说一句,我尝试将 default_url 设置为以下内容,但没有成功。
"#{Rails.root}/app/assets/images/listing_defaults/" + [version_name, "default.png"].compact.join('_')
I think the new asset pipeline is messing up the CarrierWave default method. I have the file I would like to use as my default images stored as app/assets/images/listing_defaults/default.png
.
In my Uploader, I have the following
def default_url
"assets/listing_defaults/" + [version_name, "default.png"].compact.join('_')
end
When I run my app, the image is browsable at that address (localhost:3000/assets/listing_defaults/default.png
)
For some reason though, when I try to get the default image to show up in my view, I get nothing.
<p>
<b>Images:</b>
<ul>
<% @listing.images.each do |image| -%>
<li><%= image_tag image.image_url.to_s %></li>
<% end -%>
</ul>
</p>
Yet uploaded files seem to work fine. Any ideas?
By the way, I've tried setting my default_url to the following with no luck.
"#{Rails.root}/app/assets/images/listing_defaults/" + [version_name, "default.png"].compact.join('_')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来您缺少前导斜杠:
It looks like you're missing the leading forward slash:
我刚刚修好了!我也遇到了同样的问题。
我这样称呼它...
user.avatar.tiny.url
如果附件不存在,将转到默认 URL :)
I just fixed it! I was having the same problems.
I call it like so...
user.avatar.tiny.url
That will go to the default URL if the attachment doesn't exist :)
我只是将图像放在 asset/image 文件夹和上传文件上:
查看:
I just put my image on assets/image folder, and on uploader file:
view: