Filipe Machado Carneiro Filipe Machado Carneiro - 2 months ago 16
Ruby Question

Error when I use if inside if

This is my

show.html.erb
.

I'm just trying to use an if statement within another if, when the provider is the facebook use a specific url , if the provider is google use another method.

<% if current_user %>

<%= if current_user.provider == 'google' %>
<%= image_tag "#{current_user.image}?sz=100", style: "border-radius:50px" %>
<% else %>
<%= image_tag "https://graph.facebook.com/#{current_user.uid}/picture?width=60&height=60", style: "border-radius:50px" %>
<% end %>

<%= current_user.name %>

<% else %>
<%= link_to "Logar com o Facebook", "/auth/facebook", id: "sign_in", class: "btn btn-info" %>
<%= link_to "Logar com o Google", "/auth/google_oauth2", id: "sign_in" , class: "btn btn-success" %>
<% end %>


but I'm getting this error:

Facegoogle/app/views/home/show.html.erb:5: syntax error, unexpected ')', expecting keyword_then or ';' or '\n' ...ent_user.provider == 'google' );@output_buffer.safe_append=' ... ^
/home/filipe/Sites/Facegoogle/app/views/home/show.html.erb:9: syntax error, unexpected keyword_else, expecting ')' '.freeze; else ^
/home/filipe/Sites/Facegoogle/app/views/home/show.html.erb:13: syntax error, unexpected keyword_end, expecting ')' '.freeze; end ^
/home/filipe/Sites/Facegoogle/app/views/home/show.html.erb:18: syntax error, unexpected keyword_else, expecting ')' '.freeze; else ^
/home/filipe/Sites/Facegoogle/app/views/home/show.html.erb:22: syntax error, unexpected keyword_end, expecting ')' '.freeze; end ^
/home/filipe/Sites/Facegoogle/app/views/home/show.html.erb:24: syntax error, unexpected keyword_ensure, expecting ')'
/home/filipe/Sites/Facegoogle/app/views/home/show.html.erb:26: syntax error, unexpected keyword_end, expecting ')'

Answer

You shouldn't be printing (<%=) out the if statement for google

Change the line:

<%= if current_user.provider == 'google' %>

To:

<% if current_user.provider == 'google' %>