39
41

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を複数モデルで使用し、ディレクトリごとに切り分けたいときの覚書

Posted at

はじめに

複数モデルにDeviseを使用した場合にcontrollerを切り分けたかったいし、Viewもいじりたいと思ったのでその覚書

設定ファイルの編集

/config/initializers/devise.rb
config.scoped_views = true

UserとAdminのMVCをDeviseで作成する

  • Userの作成
rails g devise user
  • Adminの作成
rails g devise admin_user

Controllerの作成(userはsiteディレクトリ以下に,adminはmanagerディレクトリ以下に作成していきます)

  • User Controllerの作成
rails g devise:controllers site/users
  • Admin Controllerの作成
rails g devise:controller manager/admin_users
  • User View の作成
rails g devise:views site/users
  • Admin View の作成
rails g devise:views manager/admin_users

ルーティングの設定

config/routes.rb
  namespace :manager do
      devise_for :admin_users, controllers: {
      sessions: 'client/admin_users/sessions',
      registrations: 'client/admin_users/registrations',
      passwords: 'client/admin_users/passwords'
    }
  end
  
    scope module: 'site' do
    devise_for :users, controllers: {
      sessions: 'site/users/sessions',
      registrations: 'site/users/registrations',
      passwords: 'site/users/passwords'
    }
  end

39
41
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
39
41

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?