ruby-on-rails - 为什么我的 View 出现语法错误?

标签 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

我试图在 if、elsif 或 else 之后添加“结束”标签,但仍然不起作用。

问候。

最佳答案

你所有的按钮都需要 <% 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 %>

关于ruby-on-rails - 为什么我的 View 出现语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31665544/

相关文章:

ruby-on-rails-3 - Rails 多态依赖 : :destroy not working correctly

debugging - 在 Rails 4 中出现错误 #<TypeError : wrong argument type nil (expected Symbol)> when using binding. pry

c - 这段代码有什么问题? (基本 C 代码)

ruby-on-rails - 地理编码器 : distance sortable index

ruby-on-rails - 创建一个根据子类的属性排序的对象数组

ruby-on-rails - 在 Rails 中使用 Postgres UUID 时避免 PG::InvalidTextRepresentation 错误

c - 在 dev c++ 中运行这段 C 时出错 - "Syntax error before * token"

ruby-on-rails - 最佳 Rails 3 XML 解析器

ruby-on-rails - 访问模型中的 Rails RESTful 路由

C错误: declaration shadows a local variable -- Won't let me repeatedly replace the value of my float variable