1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Rails】divse 新規登録とログインができない

Posted at

はじめに

この記事は備忘録として載せています。

新規登録とログインのフォーム画面のレイアウトを変更した際に、エラーが出てないのにも関わらず接続できない状態が続いていました。

環境

  • rails6.1.3.2
  • ruby2.7.3
  • devise
  • bootstrap4

結論

  • formタグの中に、fromタグを作っていたことが原因でした。

 ※フォームタグが2個ある状態

解決方法

【変更前】 formタグの中に、fromタグがあります

<%# ログイン画面 %>
<div class="sidenav">
  <div class="login-main-text">
    <h2><%= t('.sign_in') %></h2>
    <p>Login or register from here to access !</p>
  </div>
</div>
<div class="main">
  <div class="col-md-6 col-sm-12">
    <div class="login-form">
      <form>   <- ここ①
        <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>   <-ここ②

          <div class="form-group">
            <i class="fas fa-envelope"></i> <%= f.label :email %>
            <%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'form-control', placeholder: "Email" %>
          </div>

          <div class="form-group">
            <i class="fas fa-unlock"></i> <%= f.label :password %>
            <%= f.password_field :password, autocomplete: "current-password", class: 'form-control', placeholder: "Password" %>
            <% if devise_mapping.rememberable? %>
              <div class="from-group">
                <%= f.check_box :remember_me %>
                <%= f.label :remember_me %>
              </div>
            <% end %>
          </div>

          <%= link_to "新規登録", new_registration_path(resource_name), class: 'btn btn-warning text-white' %>
          <%= f.submit t('.sign_in'), class: ' btn btn-primary' %>
      </form>
      <% end %>
    </div>
  </div>
</div>

【変更後】 不要なformタグを取り除きます 

<%# ログイン画面 %>
<div class="sidenav">
  <div class="login-main-text">
    <h2><%= t('.sign_in') %></h2>
    <p>Login or register from here to access !</p>
  </div>
</div>
<div class="main">
  <div class="col-md-6 col-sm-12">
    <div class="login-form">
        <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>

          <div class="form-group">
            <i class="fas fa-envelope"></i> <%= f.label :email %>
            <%= f.email_field :email, autofocus: true, autocomplete: "email", class: 'form-control', placeholder: "Email" %>
          </div>

          <div class="form-group">
            <i class="fas fa-unlock"></i> <%= f.label :password %>
            <%= f.password_field :password, autocomplete: "current-password", class: 'form-control', placeholder: "Password" %>
            <% if devise_mapping.rememberable? %>
              <div class="from-group">
                <%= f.check_box :remember_me %>
                <%= f.label :remember_me %>
              </div>
            <% end %>
          </div>

          <%= link_to "新規登録", new_registration_path(resource_name), class: 'btn btn-warning text-white' %>
          <%= f.submit t('.sign_in'), class: ' btn btn-primary' %>
      <% end %>
    </div>
  </div>
</div>

今回は<form></form>を取り除きました。

最後に

これからも継続して学習を続けていきます!

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?