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.
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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With