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?

学習65日目

Posted at

内容

ユーザー認証機能の導入(devise)

前提

  • ruby on railsでアプリ開発中
  • 該当部分以外は省略

手順

deviseの導入

gemfile

gem 'devise'

ターミナル

bundle install

ユーザーモデル・テーブルの作成

ターミナル

rails g devise user

ターミナル

rails db:migrate

※ デフォルトのカラム以外に必要な場合は、マイグレーションファイルに追記してから実行する
(今回はnameカラムのみ追加したと想定)

ルーティングの追加

app/config/routes.rb

devise_for :users

コントローラへの記述

app/controllers/application_controller.rb

  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
  end

ビューの修正

ターミナル

rails g devise:views

app/views/devise/registrations/new.html.erb
app/views/devise/sessions/new.html.erb

<%= f.text_field :name %>

コメント

ユーザー認証の流れを知るために、gemを用いない実装方法についても学習したい。

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?