设计表单提交按钮不起作用

时间:2018-04-07 07:48:40

标签: ruby-on-rails

不确定这是否以任何方式连接,但今天早些时候我将devise gem更新为v 4.4.3

在我的注册表格中,我的设计形式略有改变:

<div class="input">
     <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
        <%= devise_error_messages! %>
      <div class="form-label font-medium ">
        Email address
      </div>
      <div class="form-input">
        <%= f.email_field :email, autofocus: true, autocomplete: "email", class: "form-control" %> <br />
      </div>

      <div class="form-label font-medium ">
        Username<br />
      </div>
      <div class="form-input">
        <%= f.text_field :username, autocomplete: "off", class: "form-control" %>  <br>
      </div>

      <div class="form-label font-medium ">
        Password<br />
      </div>
      <div class="form-input">
        <%= f.password_field :password, autocomplete: "off", class: "form-control" %><br>
      </div>

      <div class="form-label font-medium ">
        Password confirmation  <br />
      </div>
      <div class="form-input">
        <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %> <br />
      </div>
    </div>

<div class="button-inputs">
  <div class="actions flerowspb">
    <span>
      <%= f.submit "Sign up", class: "btn btn-primary", style: "width:408px;"%>
    </span>
    <% end %>
    <span>
      <%= button_to "Sign in", new_user_session_path, method: :get, class: "btn btn-info", style: "width:186px;"%>
    </span>
  </div>
</div>

点击注册链接

<%= link_to "Sign up", new_user_registration_path %>

它带我的URL:

http://localhost:3000/users/sign_up

哪个是正确的,但是当我单击表单上的提交而不填写任何字段时,除了它进入焦点scss状态之外没有任何反应。

点击之前:

enter image description here

点击后:

enter image description here

如果我然后刷新页面然后提交按钮将工作,页面刷新错误闪存消息等按预期但现在URL是:

http://localhost:3000/users然后再次按下刷新...它会转到用户索引页面。

我对此感到有些困惑,任何有关按钮发生的事情的想法都将受到赞赏。

由于

1 个答案:

答案 0 :(得分:2)

您尚未在</div>之前正确关闭div class="button-inputs">,因此请修改视图,如下所示,

<div class="input">
  <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
    <%= devise_error_messages! %>
    <div class="form-label font-medium ">
      Email address
    </div>
    <div class="form-input">
      <%= f.email_field :email, autofocus: true, autocomplete: "email", class: "form-control" %> <br />
    </div>

    <div class="form-label font-medium ">
      Username<br />
    </div>
    <div class="form-input">
      <%= f.text_field :username, autocomplete: "off", class: "form-control" %>  <br>
    </div>

    <div class="form-label font-medium ">
      Password<br />
    </div>
    <div class="form-input">
      <%= f.password_field :password, autocomplete: "off", class: "form-control" %><br>
    </div>

    <div class="form-label font-medium ">
      Password confirmation  <br />
    </div>
    <div class="form-input">
      <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %> <br />
    </div>

    <div class="button-inputs">
      <div class="actions flerowspb">
        <span>
          <%= f.submit "Sign up", class: "btn btn-primary", style: "width:408px;"%>
        </span>
        <span>
          <%= button_to "Sign in", new_user_session_path, method: :get, class: "btn btn-info", style: "width:186px;"%>
        </span>
      </div>
    </div>
  <% end %>
</div>

希望这对你有用。