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'