0
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 5 years have passed since last update.

railsでhas_secure_passwordを使うための準備

Posted at

has_secure_passwordを使うための準備について書いています。

Userモデルを例にしています。

まず、モデルでhas_secure_passwordメソッドを呼び出します。

user.rb
class User < ApplicationRecord
 has_secure_password
end

次に、メソッドを使うため、モデル内にpassword_digest属性を加えます。
コンソールに以下のコードを打ちます。

rails g migration add_password_digest_to_users password_digest:string

データベースでマイグレーションを実行することを忘れてはいけません。

rails db:migrate

続いて、gemfileにbcrypt fileを追加します。

source 'https://rubygems.org'

gem 'rails',          '5.1.6'
gem 'bcrypt',         '3.1.12'

Gemfileにfileを追加したならbundle installを行いましょう。

bundle install

以上です。

rails チュートリアル6章 https://railstutorial.jp/chapters/modeling_users?version=5.1#sec-creating_user_objects

0
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
0
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?