質問編集履歴

1

モデル情報を追記いたしました。よろしくお願いいたします。

2022/12/17 05:27

投稿

chach
chach

スコア0

test CHANGED
File without changes
test CHANGED
@@ -38,3 +38,138 @@
38
38
  end
39
39
  ```
40
40
 
41
+ ```app/models/salon.rb
42
+ class Salon < ApplicationRecord
43
+ # Include default devise modules. Others available are:
44
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
45
+ devise :database_authenticatable, :registerable,
46
+ :recoverable, :rememberable, :validatable
47
+
48
+ validates :prefecture_id, numericality: { other_than: 1, message: "can't be blank" }
49
+
50
+ # パスワード
51
+ PASSWORD_REGEX = /\A(?=.*?[a-z])(?=.*?\d)[a-z\d]+\z/i.freeze
52
+ validates :password, format: { with: PASSWORD_REGEX, message: 'には6文字以上の半角英数字を使用して設定してください' }, allow_blank: true
53
+
54
+
55
+ extend ActiveHash::Associations::ActiveRecordExtensions
56
+ belongs_to :prefecture
57
+ end
58
+ ```
59
+ ```app/models/worker.rb
60
+ class Worker < ApplicationRecord
61
+ # Include default devise modules. Others available are:
62
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
63
+ devise :database_authenticatable, :registerable,
64
+ :recoverable, :rememberable, :validatable
65
+
66
+ # ニックネーム
67
+ validates :nickname, presence: true
68
+
69
+ # パスワード
70
+ PASSWORD_REGEX = /\A(?=.*?[a-z])(?=.*?\d)[a-z\d]+\z/i.freeze
71
+ validates :password, format: { with: PASSWORD_REGEX, message: 'には6文字以上の半角英数字を使用して設定してください' }, allow_blank: true
72
+
73
+ end
74
+ ```
75
+ ```db/migrate/202212....._devise_create_workers.rb
76
+ class DeviseCreateWorkers < ActiveRecord::Migration[6.0]
77
+ def change
78
+ create_table :workers do |t|
79
+ ## Database authenticatable
80
+ t.string :worker_email, null: false
81
+ t.string :encrypted_password, null: false
82
+ t.string :nickname, null: false
83
+
84
+
85
+ ## Recoverable
86
+ t.string :reset_password_token
87
+ t.datetime :reset_password_sent_at
88
+
89
+ ## Rememberable
90
+ t.datetime :remember_created_at
91
+
92
+ ## Trackable
93
+ # t.integer :sign_in_count, default: 0, null: false
94
+ # t.datetime :current_sign_in_at
95
+ # t.datetime :last_sign_in_at
96
+ # t.string :current_sign_in_ip
97
+ # t.string :last_sign_in_ip
98
+
99
+ ## Confirmable
100
+ # t.string :confirmation_token
101
+ # t.datetime :confirmed_at
102
+ # t.datetime :confirmation_sent_at
103
+ # t.string :unconfirmed_email # Only if using reconfirmable
104
+
105
+ ## Lockable
106
+ # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
107
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
108
+ # t.datetime :locked_at
109
+
110
+
111
+ t.timestamps null: false
112
+ end
113
+
114
+ add_index :workers, :worker_email, unique: true
115
+ add_index :workers, :reset_password_token, unique: true
116
+ # add_index :workers, :confirmation_token, unique: true
117
+ # add_index :workers, :unlock_token, unique: true
118
+ end
119
+ end
120
+ ```
121
+ ```db/migrate/202212....._devise_create_salons.rb
122
+ class DeviseCreateSalons < ActiveRecord::Migration[6.0]
123
+ def change
124
+ create_table :salons do |t|
125
+ ## Database authenticatable
126
+ t.string :salon_email, null: false
127
+ t.string :encrypted_password, null: false
128
+ t.string :store_name, null: false
129
+ t.string :corporate_name, null: false
130
+ t.string :postal_code, null: false
131
+ t.integer :prefecture_id, null: false
132
+ t.string :city, null: false
133
+ t.string :street_number, null: false
134
+ t.string :building_name
135
+ t.date :established, null: false
136
+ t.integer :offices, null: false
137
+
138
+
139
+ ## Recoverable
140
+ t.string :reset_password_token
141
+ t.datetime :reset_password_sent_at
142
+
143
+ ## Rememberable
144
+ t.datetime :remember_created_at
145
+
146
+ ## Trackable
147
+ # t.integer :sign_in_count, default: 0, null: false
148
+ # t.datetime :current_sign_in_at
149
+ # t.datetime :last_sign_in_at
150
+ # t.string :current_sign_in_ip
151
+ # t.string :last_sign_in_ip
152
+
153
+ ## Confirmable
154
+ # t.string :confirmation_token
155
+ # t.datetime :confirmed_at
156
+ # t.datetime :confirmation_sent_at
157
+ # t.string :unconfirmed_email # Only if using reconfirmable
158
+
159
+ ## Lockable
160
+ # t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
161
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
162
+ # t.datetime :locked_at
163
+
164
+
165
+ t.timestamps null: false
166
+ end
167
+
168
+ add_index :salons, :salon_email, unique: true
169
+ add_index :salons, :reset_password_token, unique: true
170
+ # add_index :salons, :confirmation_token, unique: true
171
+ # add_index :salons, :unlock_token, unique: true
172
+ end
173
+ end
174
+ ```
175
+