Rails 5, “nil is not a valid asset source”

后端 未结 4 2034
暗喜
暗喜 2021-02-12 09:56

I have just upgraded to Rails 5 and I have a weird issue while trying to show an image.

I have the exact code I had for Rails 4:

<%= image_tag article         


        
4条回答
  •  悲&欢浪女
    2021-02-12 10:29

    I hope this code snippet will help those future readers.

    <%= image_tag image.picture.url, size: "100x100" unless image.picture.url.blank? %>
    

    without that unless image.picture.url.blank? part of the code,

    "nil is not a valid asset source"

    shows up when uploading empty image.

提交回复
热议问题