我如何从我的索引文件中查看活动存储上传的图像,出现这个错误。

问题描述 投票:0回答:1

<%= image_tag (complaint.image) %>这一行孕育发生了这个错误,无法将图片解析成URL:to_model委派给attachment,但attachment是nil 没有image_tag,我得到一个active_storage对象;# ,那么我怎么才能通过这个问题呢?

ruby-on-rails rails-activestorage
1个回答
0
投票

在显示图片之前,请检查它是否为nil。

<%= image_tag(complaint.image) if complaint.image %>

另外,在Ruby中,不要在方法名和parens之间加上空格。因为在Ruby中,parens是可选的,它将被视为一个单一参数,而不是一个参数列表。

foo (bar, baz) # causes a syntax error
© www.soinside.com 2019 - 2024. All rights reserved.