Alejandro Araujo
Alejandro Araujo

Reputation: 149

Why am I getting a syntax error from my view?

I'm trying to eval 3 conditional to know what button should be rendered. The code is:

            <% if action == "edit" %>
                <%= link_to '<button type="button" class="btn btn-warning"><i class="fa fa-reply"></i> Volver</button>'.html_safe, customers_path %>
                &nbsp;
                <%= button_tag(type: 'submit', class: "btn btn-success") do %>
                 <i class="fa fa-floppy-o"></i> Guardar
            <% elsif action == "show" %>
                <!--<%= link_to '<button type="button" class="btn btn-default"><i class="fa fa-pencil"></i> Editar</button>'.html_safe, edit_customer_path(@customer) %>-->
            <% elsif action == "new" %>
                <%= link_to '<button type="button" class="btn btn-warning"><i class="fa fa-reply"></i> Volver</button>'.html_safe, customers_path %>
                &nbsp;
                <%= button_tag(type: 'submit', class: "btn btn-success") do %>
                 <i class="fa fa-floppy-o"></i> Guardar
            <% end %>

I got the following error:

/home/nando/gadmon/app/views/customers/_form.html.erb:62: syntax error, unexpected keyword_elsif, expecting keyword_end '.freeze; elsif action == "show" ^ /home/nando/gadmon/app/views/customers/_form.html.erb:64: syntax error, unexpected keyword_elsif, expecting keyword_end '.freeze; elsif action == "new" ^ /home/nando/gadmon/app/views/customers/_form.html.erb:76: syntax error, unexpected keyword_ensure, expecting keyword_end /home/nando/gadmon/app/views/customers/_form.html.erb:78: syntax error, unexpected end-of-input, expecting keyword_end

I was trying to add "end" tag after if, elsif or else and still doesnt work.

Regards.

Upvotes: 3

Views: 835

Answers (1)

Alexandre Voyer
Alexandre Voyer

Reputation: 819

all your buttons needs <% end %>

<% if action == "edit" %>
  <%= link_to '<button type="button" class="btn btn-warning"><i class="fa fa-reply"></i> Volver</button>'.html_safe, customers_path %>
            &nbsp;
  <%= button_tag(type: 'submit', class: "btn btn-success") do %>
     <i class="fa fa-floppy-o"></i> Guardar
  <% end %>            
<% elsif action == "show" %>
  <!--<%= link_to '<button type="button" class="btn btn-default"><i class="fa fa-pencil"></i> Editar</button>'.html_safe, edit_customer_path(@customer) %>-->
<% elsif action == "new" %>
  <%= link_to '<button type="button" class="btn btn-warning"><i class="fa fa-reply"></i> Volver</button>'.html_safe, customers_path %>
            &nbsp;
  <%= button_tag(type: 'submit', class: "btn btn-success") do %>
             <i class="fa fa-floppy-o"></i> Guardar
  <% end %>
<% end %>

Upvotes: 2

Related Questions