6

I have the following code:

<tbody>
   <%= Item.each do |item|=%>
   <tr>
      <th><%= item.rev =%></th>      <=========
      <th><%= item.name =%></th>
   </tr>
   <%= end =%>
</tbody>

However I am getting a syntax error on the inidcated line. There is data in the database(Test case). No idea what I am doing wrong.

2 Answers 2

15

The equals to signs you have are wrong. Try as below:

<tbody>
   <% Item.each do |item|%>
   <tr>
      <th><%= item.rev %></th>     
      <th><%= item.name %></th>
   </tr>
   <% end %>
</tbody>

The <%= should only be used for expressions that need to be evaluated.

To help understand embedded ruby see this link http://www.ruby-doc.org/docs/ProgrammingRuby/html/web.html

Sign up to request clarification or add additional context in comments.

Comments

1

The expression for erb tags is <% #code %>
now if we want to print that tag too then we apply <%= #code %>
i.e. only one '=' sign is used and that too on left side.
Also in line each iterator there nothing can be printed, hence no '=' sign in that line, similar is the case with tags containing 'end'.

Hence your code should look like

<tbody>
     <% Item.each do |item| %>
          <tr>
               <th><%= item.rev %></th>
               <th><%= item.name %></th>
          </tr>
     <% end %>
</tbody>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.