0

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?

2 Answers 2

1

Use <%, not <%=, the statement doesn't return anything.

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

2 Comments

Holy lord! All that for an =. Thank you!
The equal sign means you want to "echo" out the result. It's not appropriate on an if statement like you have. Same goes for ends and elses and anything that can't be output (returned).
0

Can you remove the = from the <%= on <%= if @my_items.count >= 5 %> it may be an issue on how ERB handles conditionals and <%= %> rather than <% %>

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.