現在、Railsにdeviseを導入し、複数モデルを作成しています。
テーブル:worker、salonの2つで作成中。
ローカル環境でsign_inの画面に直接アクセスすると、どちらも
ActionController::RoutingError (uninitialized constant Salons)
ActionController::RoutingError (uninitialized constant Workers):
のエラーが出ます。
上記エラー解消方法をご教示いただきたいです。
発生している問題・エラーメッセージ
該当のソースコード
config/routes.rb
1Rails.application.routes.draw do 2 devise_for :salons, controllers: { 3 sessions: 'salons/sessions', 4 passwords: 'salons/passwords', 5 registrations: 'salons/registrations' 6 } 7 devise_for :workers, controllers: { 8 sessions: 'workers/sessions', 9 passwords: 'workers/passwords', 10 registrations: 'workers/registrations' 11 } 12 root to: 'home#index' 13end
app/controllers/salons_controller.rb
1class SalonsController < ApplicationController 2end
app/controllers/workers_controller.rb
1class WorkersController < ApplicationController 2end
app/models/salon.rb
1class Salon < ApplicationRecord 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :validatable 6 7 validates :prefecture_id, numericality: { other_than: 1, message: "can't be blank" } 8 9 # パスワード 10 PASSWORD_REGEX = /\A(?=.*?[a-z])(?=.*?\d)[a-z\d]+\z/i.freeze 11 validates :password, format: { with: PASSWORD_REGEX, message: 'には6文字以上の半角英数字を使用して設定してください' }, allow_blank: true 12 13 14 extend ActiveHash::Associations::ActiveRecordExtensions 15 belongs_to :prefecture 16end
app/models/worker.rb
1class Worker < ApplicationRecord 2 # Include default devise modules. Others available are: 3 # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable 4 devise :database_authenticatable, :registerable, 5 :recoverable, :rememberable, :validatable 6 7 # ニックネーム 8 validates :nickname, presence: true 9 10 # パスワード 11 PASSWORD_REGEX = /\A(?=.*?[a-z])(?=.*?\d)[a-z\d]+\z/i.freeze 12 validates :password, format: { with: PASSWORD_REGEX, message: 'には6文字以上の半角英数字を使用して設定してください' }, allow_blank: true 13 14end
db/migrate/202212....._devise_create_workers.rb
1class DeviseCreateWorkers < ActiveRecord::Migration[6.0] 2 def change 3 create_table :workers do |t| 4 ## Database authenticatable 5 t.string :worker_email, null: false 6 t.string :encrypted_password, null: false 7 t.string :nickname, null: false 8 9 10 ## Recoverable 11 t.string :reset_password_token 12 t.datetime :reset_password_sent_at 13 14 ## Rememberable 15 t.datetime :remember_created_at 16 17 ## Trackable 18 # t.integer :sign_in_count, default: 0, null: false 19 # t.datetime :current_sign_in_at 20 # t.datetime :last_sign_in_at 21 # t.string :current_sign_in_ip 22 # t.string :last_sign_in_ip 23 24 ## Confirmable 25 # t.string :confirmation_token 26 # t.datetime :confirmed_at 27 # t.datetime :confirmation_sent_at 28 # t.string :unconfirmed_email # Only if using reconfirmable 29 30 ## Lockable 31 # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 32 # t.string :unlock_token # Only if unlock strategy is :email or :both 33 # t.datetime :locked_at 34 35 36 t.timestamps null: false 37 end 38 39 add_index :workers, :worker_email, unique: true 40 add_index :workers, :reset_password_token, unique: true 41 # add_index :workers, :confirmation_token, unique: true 42 # add_index :workers, :unlock_token, unique: true 43 end 44end
db/migrate/202212....._devise_create_salons.rb
1class DeviseCreateSalons < ActiveRecord::Migration[6.0] 2 def change 3 create_table :salons do |t| 4 ## Database authenticatable 5 t.string :salon_email, null: false 6 t.string :encrypted_password, null: false 7 t.string :store_name, null: false 8 t.string :corporate_name, null: false 9 t.string :postal_code, null: false 10 t.integer :prefecture_id, null: false 11 t.string :city, null: false 12 t.string :street_number, null: false 13 t.string :building_name 14 t.date :established, null: false 15 t.integer :offices, null: false 16 17 18 ## Recoverable 19 t.string :reset_password_token 20 t.datetime :reset_password_sent_at 21 22 ## Rememberable 23 t.datetime :remember_created_at 24 25 ## Trackable 26 # t.integer :sign_in_count, default: 0, null: false 27 # t.datetime :current_sign_in_at 28 # t.datetime :last_sign_in_at 29 # t.string :current_sign_in_ip 30 # t.string :last_sign_in_ip 31 32 ## Confirmable 33 # t.string :confirmation_token 34 # t.datetime :confirmed_at 35 # t.datetime :confirmation_sent_at 36 # t.string :unconfirmed_email # Only if using reconfirmable 37 38 ## Lockable 39 # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts 40 # t.string :unlock_token # Only if unlock strategy is :email or :both 41 # t.datetime :locked_at 42 43 44 t.timestamps null: false 45 end 46 47 add_index :salons, :salon_email, unique: true 48 add_index :salons, :reset_password_token, unique: true 49 # add_index :salons, :confirmation_token, unique: true 50 # add_index :salons, :unlock_token, unique: true 51 end 52end
回答1件