为什么我从视图中收到语法错误?

时间:2015-07-28 00:26:07

标签: ruby-on-rails ruby-on-rails-4 syntax-error

我试图评估3条件以了​​解应该呈现什么按钮。代码是:

            <% 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 %>

我收到以下错误:

/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

我试图添加&#34;结束&#34;如果,elsif或其他仍然无法正常工作。

问候。

1 个答案:

答案 0 :(得分:2)

所有按钮需要&lt;%end%&gt;

<% 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 %>