Ruby on rails 如何创建一个链接,并在表单中添加一个操作按钮?

Ruby on rails 如何创建一个链接,并在表单中添加一个操作按钮?,ruby-on-rails,forms,link-to,Ruby On Rails,Forms,Link To,我有一个叫做用户的资源。在编辑操作中,我有一个表单用于编辑用户信息。我想在表单中放置一个按钮以重定向到另一个操作。因此,我正在这样做: <%= form_for @user, html: {class: 'form-horizontal'} do |f| %> <div class="row"> <div class="col-sm-8 col-sm-offset-2"> <div class="form-group">

我有一个叫做用户的资源。在编辑操作中,我有一个表单用于编辑用户信息。我想在表单中放置一个按钮以重定向到另一个操作。因此,我正在这样做:

<%= form_for @user, html: {class: 'form-horizontal'} do |f| %>
<div class="row">
  <div class="col-sm-8 col-sm-offset-2">

    <div class="form-group">
      <%= f.label :name, "Name", class: "col-sm-4 control-label"%>
      <div class="col-sm-8">
        <%= f.text_field :name, required: "required", class: "form-control" %>
      </div>
    </div>

    <div class="form-group">
      <%= f.label :email, "Email", class: "col-sm-4 control-label"%>
      <div class="col-sm-8">
        <%= f.email_field :email, required: "required", class: "form-control" %>
      </div>
    </div>

    <div class="form-group">
      <%= link_to root_path do %>
        <button class="btn btn-default" name="button">Go to Root</button>
      <% end %>
    </div>

    <%= f.submit "Save", class: "btn btn-default" %>

  </div>
</div>
<% end %>

扎根
问题是,当我单击“转到根目录”按钮时,它会在更新操作中处理表单,就像我按下了提交按钮一样。但如果我改变

<div class="form-group">
      <%= link_to root_path do %>
        <button class="btn btn-default" name="button">Go to Root</button>
      <% end %>
    </div>

扎根
为了


扎根

它将转到te root_路径。为什么会发生这种情况,为什么我不能使用创建指向此表单中另一个操作的链接?

默认情况下,表单按钮的类型为submit。您需要指定按钮的类型

请尝试以下操作:

<button type="button" class="btn btn-default" name="button">Go to Root</button>
转到根目录

有没有办法在表单中使用ruby标记来实现这一点??例如:
<button type="button" class="btn btn-default" name="button">Go to Root</button>