I have a basic to do app and am trying to show the most recent 4 lists on the homepage, then link to "See X more..." at the bottom. The logic worked perfectly if there were 5 or more lists, but when there were 4 or fewer I would get "See 0 more..." or "See -3 more..." which obviously isn't right, so I added an if statement with the same basic components, but got this very complex syntax error:
syntax error, unexpected ')', expecting keyword_then or ';' or '\n'
...end=( if @my_items.count >= 5 );@output_buffer.safe_append='
... ^
/Users/.../app/views/home/index.html.erb:50: syntax error, unexpected keyword_end, expecting ')'
'.freeze; end
^
/Users/.../app/views/home/index.html.erb:103: syntax error, unexpected keyword_else, expecting ')'
'.freeze; else
^
/Users/.../app/views/home/index.html.erb:122: syntax error, unexpected keyword_end, expecting ')'
'.freeze; end
^
/Users/.../app/views/home/index.html.erb:125: syntax error, unexpected keyword_ensure, expecting ')'
/Users/.../app/views/home/index.html.erb:127: syntax error, unexpected keyword_end, expecting ')'
Here's the code, with the problematic line indicated:
<% @top_items.each do |item| %>
<% if item.user_id == current_user.id %>
<p>☐ <%= item.name %></p>
<% end %>
<% end %>
<p class="text-center">
<%= if @my_items.count >= 5 %> <<<<<<THIS IS THE PROBLEM LINE
<%= link_to lists_path do %>See <%= @my_items.count.count - 4 %> More...<% end %>
<% end %>
</p>
Just to clarify, if I comment out the problem line and it's corresponding `<% end %> the page shows error free. Anyone understand what is going wrong here?