質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

8103閲覧

deviseでログインができない

satail

総合スコア31

Devise

Deviseとは、Ruby-on-Railsの認証機能を追加するプラグインです。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2017/07/08 05:52

###前提・実現したいこと
deviseでログインをしたところ、エラーも出さずログインできずにそのままログイン画面に止まってしまいます。rails cでユーザーが保存されていることも確認しましたが、何も問題ありません。
ログインボタンを押したときのログも確認しましたが、特にエラーも見当たりませんでした。
ログインできるようにするにはどうしたらよろしいでしょうか?

###該当のソースコード

ActiveRecord::Schema.define(version: 20170707154233) do create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.string "confirmation_token" t.datetime "confirmed_at" t.datetime "confirmation_sent_at" t.string "unconfirmed_email" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "name", default: "", null: false t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end end

sessions.html.erb

<div class="row"> <div class="col-lg-8"> <div class="bs-component"> <form> <fieldset> <legend>Sign in</legend> <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> <div class="form-group"> <label for="exampleInputEmail1"><%= f.label :email %></label> <div aria-describedby="emailHelp" placeholder="Enter email"> <%= f.email_field :email, autofocus: true, class: "form-control", id: "exampleInputEmail1" %> </div> </div> <div class="form-group"> <label for="exampleInputPassword1"><%= f.label :password %></label> <div placeholder="Password"> <%= f.password_field :password, autocomplete: "off", class: "form-control", id: "exampleInputPassword1" %> </div> </div> <% if devise_mapping.rememberable? -%> <div class="form-group"> <%= f.check_box :remember_me %> <%= f.label :remember_me %> </div> <% end -%> <div class="actions"> <%= f.submit "Log in", class: "btn btn-primary" %> </div> <% end %> </fieldset> </form> </div> </div> </div> <%= render "devise/shared/links" %>

seeds/users.rb

names = %w(Kyouko,,,,) 0.upto(9) do |x| user = User.create( name: names[x], email: "#{names[x]}@example.com", password: "password", password_confirmation: "password" ) user.skip_confirmation! user.save! end

User.rb

class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable validates :name, presence: true, length: { maximum: 50 } end

routes.rb

Rails.application.routes.draw do devise_for :users root to: "top#index" get "about" => "top#about", as: "about" resources :users, only: [:index, :show] end

###試したこと
こちらを参考にしています。
###補足情報(言語/FW/ツール等のバージョンなど)
Rails 5.0.4

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

改めて、フォームのレイアウトを行ったら認証できてなかったので、rake db:resetを行ってログインできるようになりました。ただ、seeds/users.rbを作成した後すでに行ったはずだったのですが、、、よく原因がわかりません。

投稿2017/07/08 07:43

satail

総合スコア31

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問