Unexpected pitfalls when images cannot be displayed

Work content

I want to display the posted image

I was worried about the error in the situation that other than the image is displayed

Syntax error

ActionView::SyntaxErrorInTemplate in PrototypesController#index

Error location

Only the error part is described


<%= image_tag prototype.image, if prototype.image.attached? %>

At first there was a little more description, but I forgot.

The description that I referred to

<%= image_tag message.image, class: 'message-image' if message.image.attached? %>

The difference is that it contains classes.

I wrote it in the version without the class, but I got an error.

Do you know why you got the error?

It's not spelled differently.

Solutions

Do you know what's different?

<%= image_tag prototype.image if prototype.image.attached? %>

The cause of the error statement is often simple, so it seems like when it was resolved.

When you're worried, it's hard to be honest.

But if you get over it, you can grow!

Keep it on.

You didn't need ",". I didn't use it when using the If statement, but I needed it when using the class.

"," Was a blind spot.

I thought it was necessary, so I learned that it is important to remove even the ones that I think are necessary.

Thank you!

Recommended Posts

Unexpected pitfalls when images cannot be displayed
Measures when model cannot be created
"ClassNotFoundException" is displayed when tomcat is started in eclipse and cannot be started
[Rails] Posts cannot be deleted when commented! ??
[Android] Solution when the camera cannot be started on Android 9
What to do when Git Repository cannot be displayed in Team Explorer for Eclipse in Azure
Note when pip install mysqlclient cannot be installed on Mac