11
16

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.

devise, controllerの継承, ルーティングの設定

Posted at

devise

sign_inの振る舞いを変更

Userモデルのsession_contollerを変更したいので, コントローラを作成して,

rails g controller users/sessions

DeviseのSessionsContollerを継承しておく.

class Users::SessionsController < Devise::SessionsController

あとはメソッドをオーバーライドして振る舞いを変える.

sign_upの振る舞いを変更

同様に

rails g contoller users/registrations

継承元を以下のように変更.

class Users::RegistrationsController < Devise::RegistrationsController

作成したコントローラのルーティングを設定

routes.rbに以下の項目を追加する.

routes.rb
devise_for :users, :controllers => {
    :sessions => 'users/sessions' ,
    :registrations => 'users/registrations'
}

devise側で用意されてるインスタンス

ログインしてないユーザーをログイン画面に飛ばす(controllerで)

before_filter :authenticate_user!

ログインしてるユーザー(viewで)

current_user
11
16
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
11
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?