我使用rails composer工具創建了一個rails設計組合項目,其中包含可確認的rails。Rails composer devise-rails不會讓我完成rails db:reset
這是一切優秀 - 然後我決定,我想執行一個rails db:reset
我跑的命令,這是輸出:
Andys-MacBook-Pro:myproj andyarmstrong$ rails db:reset
Dropped database 'myproj_development'
Dropped database 'myproj_test'
Created database 'myproj_development'
Created database 'myproj_test'
-- enable_extension("plpgsql")
-> 0.0419s
-- create_table("users", {:force=>:cascade})
-> 0.0188s
-- enable_extension("plpgsql")
-> 0.0305s
-- create_table("users", {:force=>:cascade})
-> 0.0236s
rails aborted!
NoMethodError: undefined method `confirm!' for #<User:0x007fa47ac1c2a0>
Did you mean? confirm
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activemodel-5.1.0.rc1/lib/active_model/attribute_methods.rb:432:in `method_missing'
/Users/andyarmstrong/Documents/Personal/myproj/app/services/create_admin_service.rb:6:in `block in call'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/core.rb:339:in `initialize'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/devise-4.2.1/lib/devise/models/confirmable.rb:65:in `initialize'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/inheritance.rb:66:in `new'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/inheritance.rb:66:in `new'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/persistence.rb:50:in `create!'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/relation.rb:156:in `block in create!'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/relation.rb:337:in `scoping'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/relation.rb:156:in `create!'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/relation.rb:227:in `find_or_create_by!'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/querying.rb:6:in `find_or_create_by!'
/Users/andyarmstrong/Documents/Personal/myproj/app/services/create_admin_service.rb:3:in `call'
/Users/andyarmstrong/Documents/Personal/myproj/db/seeds.rb:8:in `<top (required)>'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activesupport-5.1.0.rc1/lib/active_support/dependencies.rb:286:in `load'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activesupport-5.1.0.rc1/lib/active_support/dependencies.rb:286:in `block in load'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activesupport-5.1.0.rc1/lib/active_support/dependencies.rb:258:in `load_dependency'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activesupport-5.1.0.rc1/lib/active_support/dependencies.rb:286:in `load'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/railties-5.1.0.rc1/lib/rails/engine.rb:549:in `load_seed'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/tasks/database_tasks.rb:268:in `load_seed'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/activerecord-5.1.0.rc1/lib/active_record/railties/databases.rake:181:in `block (2 levels) in <top (required)>'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/railties-5.1.0.rc1/lib/rails/commands/rake/rake_command.rb:21:in `block in perform'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/railties-5.1.0.rc1/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/railties-5.1.0.rc1/lib/rails/command.rb:46:in `invoke'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/railties-5.1.0.rc1/lib/rails/commands.rb:16:in `<top (required)>'
/Users/andyarmstrong/Documents/Personal/myproj/bin/rails:9:in `require'
/Users/andyarmstrong/Documents/Personal/myproj/bin/rails:9:in `<top (required)>'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `load'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/spring-2.0.1/lib/spring/client/rails.rb:28:in `call'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/spring-2.0.1/lib/spring/client/command.rb:7:in `call'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/spring-2.0.1/lib/spring/client.rb:30:in `run'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/spring-2.0.1/bin/spring:49:in `<top (required)>'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `load'
/Users/andyarmstrong/.rvm/gems/[email protected]/gems/spring-2.0.1/lib/spring/binstub.rb:31:in `<top (required)>'
/Users/andyarmstrong/Documents/Personal/myproj/bin/spring:15:in `require'
/Users/andyarmstrong/Documents/Personal/myproj/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
繼通過堆棧跟蹤 - 我認爲這是失敗db:seeds組件,在這一行:user = CreateAdminService.new.call
。如果我再進入應用程序/服務,並打開create_admin_service.rb文件,我們終於可以看到我們的問題行:
class CreateAdminService
def call
user = User.find_or_create_by!(email: Rails.application.secrets.admin_email) do |user|
user.password = Rails.application.secrets.admin_password
user.password_confirmation = Rails.application.secrets.admin_password
user.confirm!
end
end
end
爲什麼user.confirm!找不到?這是不是意味着成爲基礎Devise包的一部分?作爲參考,這是我的用戶模型:
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :confirmable,
:recoverable, :rememberable, :trackable, :validatable
end