Reputation: 1470
Hi I am trying to convert haml to erb not sure where i am going wrong, following is my HAML code
%h1 All Movies
%table#movies
%thead
%tr
%th{:class => ('hilite' if @sort == 'title') }
= link_to 'Movie Title', movies_path(:sort_param => 'title'), :id => 'title_header'
%th{:class => ('hilite' if @sort == 'release_date') }
= link_to 'Release Date', movies_path(:sort_param => 'release_date'), :id=> 'release_date_header'
%th Release Date
%th More Info
%th Edit Info
%tbody
- @movies.each do |movie|
%tr
%td= movie.title
%td= movie.rating
%td= movie.release_date
%td= link_to "More about #{movie.title}", movie_path(movie)
%td= link_to "Edit Movie", edit_movie_path(movie)
= link_to 'ADD NEW MOVIE', new_movie_path
And below is my erb code
<h1> All Movies </h1>
<table id='movies'>
<thead>
<tr>
<th class ='hilite'><%= if @sort == 'title'
link_to movies_path(:sort_param => 'title'), :id => 'title_header'
end %></th>
<th class = 'hilite'><%=if @sort == 'release_date'
link_to movies_path(:sort_param => 'release_date'), :id=> 'release_date_header' end %> </th>
<th> Release Date </th>
<th> More Info </th>
<th> Edit Info </th>
</tr>
</thead>
<tbody>
<%= @movies.each do |movie| %>
<tr>
<td><%= movie.title %> </td>
<td><%= movie.rating %> </td>
<td><%= movie.release_date %> </td>
<td><%= link_to "More about #{movie.title}", movie_path(movie) %>
<td><%= link_to "Edit Movie", edit_movie_path(movie) %></td>
</tr>
<%= end %>
<%= link_to 'ADD NEW MOVIE', new_movie_path %>
</tbody>
</table>
This is the error i am getting,
appname/app/views/movies/index.html.erb:25: syntax error, unexpected keyword_end
');@output_buffer.append= ( end );@output_buffer.safe_concat('
^
appname/app/views/movies/index.html.erb:30: syntax error, unexpected keyword_ensure, expecting ')'
appname/app/views/movies/index.html.erb:32: syntax error, unexpected keyword_end, expecting ')'
Upvotes: 1
Views: 228
Reputation: 38645
The problem seems to be you are using <%=
on each
call and end
. Remove the equals sign =
from both as follows:
<% @movies.each do |movie| %>
<tr>
<td><%= movie.title %> </td>
<td><%= movie.rating %> </td>
<td><%= movie.release_date %> </td>
<td><%= link_to "More about #{movie.title}", movie_path(movie) %>
<td><%= link_to "Edit Movie", edit_movie_path(movie) %></td>
</tr>
<% end %>
Note that <%= %>
is used to print what you have in between them.
Addition :
Also when you are using one liner if
statement like you have used i.e. <%= if ...
you need to use if...then...end
syntax like follows:
<th class ='hilite'><%= if @sort == 'title' then link_to movies_path(:sort_param => 'title'), :id => 'title_header' end %></th>
<th class = 'hilite'><%= if @sort == 'release_date' then link_to movies_path(:sort_param => 'release_date'), :id=> 'release_date_header' end %></th>
Upvotes: 3