Varshini
Varshini

Reputation: 153

Why does my Rails app break when I use image_tag to display a photo on Rails 6?

I'm currently taking an online course on Rails and I'm using the Carrierwave gem to have a photo uploading function on a test restaurant review site. When I type the following code:

<%= @review.photo %>

The output is:

/uploads/review/photo/12/aqua-roma-aqua-tokyo.jpg

However, when I add the image_tag

<%= image_tag @review.photo %>

The output gives me the following error:

Can't resolve image into URL: undefined method `to_model' for #PhotoUploader:0x00007fc684572ec8 Did you mean? to_xml

Upvotes: 0

Views: 111

Answers (2)

nourza
nourza

Reputation: 2321

Add url to the image

 <%= image_tag @review.image.url %>

Upvotes: 0

dileep nandanam
dileep nandanam

Reputation: 2895

With carrierwave, displaying image should be like

= image_tag( @review.photo.url)

Upvotes: 1

Related Questions