仅在rails应用程序中显示图像时才显示该图像

时间:2014-05-01 09:55:40

标签: ruby-on-rails ruby-on-rails-3

我的网站上有一个博客页面,有些帖子有图片,有些则没有。如果没有图像则显示错误,因此我将代码更改为仅显示图像是否存在

.post_body
    = @post.body.html_safe
    - if @post.image
      = filepicker_image_tag @post.image, w: 208, h: 208, fit: 'clip'

在我的本地主机上,这很好地解决了问题,如果我没有在帖子中添加图像,则不会显示任何内容。但是当我将它推送到heroku时,我的代码更改没有任何区别。如果帖子上没有图像,则会显示损坏的图像图标。

有谁知道为什么在本地主机上没有问题,但不能在线?

由于

1 个答案:

答案 0 :(得分:2)

添加条件,像这样

filepicker_image_tag @post.image, w: 208, h: 208, fit: 'clip' unless @post.image.blank?

.post_body
    = @post.body.html_safe
    - if @post.image.present?
      = filepicker_image_tag @post.image, w: 208, h: 208, fit: 'clip'
相关问题