bin/rails db:migrateコマンドを入力するとターミナルで以下のようなエラー文が。
Creating staff_members....
rails aborted!
ActiveModel::UnknownAttributeError: unknown attribute 'password' for StaffMember.
StaffMemberのpasswordが存在しないよと仰ってます。
最初にmigrationファイルを疑ってかかるも、passwordに関する記述は間違っていませんでした。続いてモデルを見に行くことに。
staff_member.rb
class StaffMember < ApplicationRecord
include EmailHolder
include PersonalNameHolder
has_many :events, class_name:"StaffEvent", dependent: :destroy
validates :start_date ,presence: true , date:{
after_or_equal_to: Date.new(2000,1,1),
before: -> (obj) { 1.year.from_now.to_date },
allow_blank: true
}
validates :end_date, date: {
after: :start_date,
before: -> (obj) { 1.year.from_now.to_date },
allow_blank: true
}
def active?
!suspended && start_date <= Date.today &&
(end_date.nil? || end_date > Date.today)
end
end
PasswordHolderというmoduleを継承していないことが判明しました。
staff_member.rb
class StaffMember < ApplicationRecord
include EmailHolder
include PersonalNameHolder
include PasswordHolder <=ここを追記
has_many :events, class_name:"StaffEvent", dependent: :destroy
validates :start_date ,presence: true , date:{
after_or_equal_to: Date.new(2000,1,1),
before: -> (obj) { 1.year.from_now.to_date },
allow_blank: true
}
validates :end_date, date: {
after: :start_date,
before: -> (obj) { 1.year.from_now.to_date },
allow_blank: true
}
def active?
!suspended && start_date <= Date.today &&
(end_date.nil? || end_date > Date.today)
end
end
エラーが解消しました。
bash-4.4$ bin/rails db:reset
Dropped database 'baukis2_development'
Dropped database 'baukis2_test'
Created database 'baukis2_development'
Created database 'baukis2_test'
Creating staff_members....
Creating administrators....
Creating staff_events....
Creating customers....
bash-4.4$