Tuma
Tuma

Reputation: 807

"syntax error, unexpected ')'" in .html.erb file, after if statement

I have a .html.erb file that's supposed to print a message when a certain parameter is "true" and another when it's "false". This is the code for the file:

<%= if params[:result] == "true" %>
    <h1>Success</h1>
    <p>The words <%=params[:first] %> and <%= params[:second] %> are anagrams! <br>
<%= else %>
    <h1>Oh no!</h1>
    <p>The words <%=params[:first] %> and <%= params[:second] %> are not anagrams. <br>
<br>
<%= link_to 'Try another pair', welcome_index_path%>

But I get this error:

/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:3: syntax error, unexpected ')', expecting keyword_then or ';' or '\n' if @result == "true" );@output_buffer.safe_append=' 

/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:6: syntax error, unexpected keyword_else '.freeze;@output_buffer.append=( else );@output_buffer.safe_append=' 

/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:11: syntax error, unexpected keyword_ensure, expecting ')' 

/home/mariana/Documents/RD-anagram/anagram/app/views/solver/result.html.erb:13: syntax error, unexpected keyword_end, expecting ')'

Upvotes: 1

Views: 1496

Answers (2)

Apoorv
Apoorv

Reputation: 1389

Copy the follwing code

<% if params[:result] %>
<h1>Success</h1>
<p>The words <%=params[:first] %> and <%= params[:second] %> are  anagrams! <br>
<%else %>
<h1>Oh no!</h1>
<p>The words <%=params[:first] %> and <%= params[:second] %> are not anagrams. <br>
<%end%>


Upvotes: -1

Shani
Shani

Reputation: 2541

if statement should be like this. Removing <%= if %> to <% if %> should work.

<% if %> 

<% else %>

<% end %>

Upvotes: 6

Related Questions