Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 仅当图像为';rails应用程序中存在的_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 仅当图像为';rails应用程序中存在的

Ruby on rails 仅当图像为';rails应用程序中存在的,ruby-on-rails,ruby-on-rails-3,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时,我的代码更改

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

.post_body
    = @post.body.html_safe
    - if @post.image
      = filepicker_image_tag @post.image, w: 208, h: 208, fit: 'clip'
在我的本地主机上,这很好地解决了这个问题,如果我没有在帖子中添加图像,就不会显示任何内容。但当我把它推给heroku时,我的代码更改并没有带来任何影响。如果帖子上没有图像,则会显示一个损坏的图像图标

有人知道为什么在localhost中这样做很好,但不在线吗


谢谢

添加条件,如下所示

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


谢谢,成功了!你能解释一下为什么仅仅说“if post.image”是不够的吗?
.post_body
    = @post.body.html_safe
    - if @post.image.present?
      = filepicker_image_tag @post.image, w: 208, h: 208, fit: 'clip'