LoginSignup
1
2

More than 3 years have passed since last update.

deviseにユーザー詳細や編集機能を付ける

Posted at

はじめに

deviseを使ってログイン機能を作った後にユーザー情報のページを実装したいと思い作ってみたら変なところで詰まったので書いておくことにしました。(備忘録)

前提

gem 'devise' でログイン機能実装済み(email,password)

ユーザーの一覧ページを作る

$ rails g controller users index
routes.rb
devise_for :users
resources :users

resourcesをdivise_forの下に書く。上に書くとdeviceが優先されてログイン、ログアウトの時にidが変なところに入ってバグる。

indexページのルーティングとビューは各々好きに作る。

カラムの追加

$ add_name_to_users name:string
$ rails db:migrate

この呪文をいつも忘れてググってるのでここに書いておくことにしました。名前以外にも色々追加する。

機能実装

詳細、編集、削除を実装して完成。

1
2
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
2