Home>

When I tried to display an image on the top page using image_tag,
ActionView :: SyntaxErrorInTemplate cannot be resolved.

ActionView :: SyntaxErrorInTemplate in PrototypesController # index
Encountered a syntax error while rendering template: check<% = link_to image_tag (prototype.image, class :: cardimg) prototype_path (@ prototype.id)%>body "><% = link_to'prototype.title', prototype_path (@ prototype.id), class :: cardtitle%>

summary "><% = prototype.catch_copy%>

<% = link_to" by # {prototype.user.name} ", prototype_path (@ prototype.id), class:: card__user%>

Error message
Corresponding source code

app/views/prototypes/_prototype.html.erb


<% = link_to image_tag (prototype.image, class:: card__img) prototype_path (@ prototype.id)%>
  
  <% = link_to'prototype.title', prototype_path (@ prototype.id), class:: card__title%>
  <p>
    <% = prototype.catch_copy%>
  </p>
  <% = link_to "by # {prototype.user.name}", prototype_path (@ prototype.id), class:: card__user%>
  


app/controllers/prototypes_controller.rb

class PrototypesController</pre>
<p><br />
app/models/prototype.rb</p>
<pre><code data-language = "Ruby">class Prototype</pre>
<p><br />
app/views/prototypes/index.html.erb</p>
<pre><code data-language = "Ruby"><main>
  
  <% if user_signed_in?%>
      
        Hello,
      <% = link_to "# {current_user.name}", root_path, class:: greeting__link%>
      
  <% end%>
    
    <% = render'prototype', collection: @prototypes%>
    
  
</main>


config/routes.rb

Rails.application.routes.draw do
  devise_for: users
  root to:'prototypes # index'
  resources: prototypes, only: [: index,: new,: create,: show]
end
What I tried

I thought that I couldn't get it in prototype.image because the association was wrong, so I reviewed the association.
I also reviewed the usage of link_to and image_tag, but I don't understand the mistake.

  • Answer # 1

    The error message is as follows.

    <% = link_to image_tag (prototype.image, class:: card__img) prototype_path (@ prototype.id)%>

    This part is not grammatically valid. Perhaps it looks like this:

    <% = link_to image_tag (prototype.image, class:: card__img), prototype_path (@ prototype.id)%>