If 语句阻止提交按钮工作

If statement preventing submit button to work

由于第一个 if 语句,我的提交按钮不起作用。如果我移除该块,该按钮将起作用。该声明似乎打破了这一观点。为什么?

<% if params[:action] == "edit" %>
    <div class="field">
      <%= form_tag :action => "edit" do %>
        <%= select_tag :vehicle_id, options_from_collection_for_select(@vehicles, :id, :model, params[:id].to_i), :onchange => "this.form.submit()" %> 
      <% end -%>
      <%= link_to 'Nouvelle voiture', new_vehicle_path %>
    </div>
  <% end -%>

  <div class="field">
    <%= f.label "Modèle" %>
    <%= f.text_field :model, required: true %>
  </div>
  <div class="field">
    <%= f.label "Immatriculation" %>
    <%= f.text_field :license_plate, required: true %>
  </div>
  <div class="field">
    <%= f.label "Complément" %>
    <%= f.text_field :complement, required: true%>
  </div>
  <div class="field">
    <%= f.label "Puissance CV" %>
    <%= f.number_field :horse_power, required: true %>
  </div>
  <div class="field">
    <%= f.label "Indemnité KM" %>
    <%= f.number_field :km_compensation, required: true%>
  </div>

  <% if params[:action] == "edit" %>
    <%= link_to 'Détruire', @vehicle, method: :delete, data: { confirm: 'Êtes-vous sûr ? Les trajets associés seront aussi détruits.' } %>
    <h1>Trajets</h1>

    <div>
      <span>Clients</span>
      <span>Kms aller/retour</span>
    </div> 

    <%= f.fields_for :trip_distances do |builder| %>   
        <div class="field">
          <%= builder.text_field :id_contract %>
          <%= builder.number_field :length %>
        </div>
    <% end -%>
  <% end -%>

  <div class="actions">
    <%= f.submit 'Sauvegarder' %>
  </div>

当您输入 if 语句时,您没有包含提交按钮的表单。没有 if 声明您的表单在视图中,您可以提交给它。

找到解决方案。我不需要 form_tag:

  <%= form_tag :action => "edit" do %>