2017-03-31 16 views
0

私は、レールコンポーザーツールを使用してレールを確認しました。Railsコンポーザーdevise-railsはレールDBを完成させません:

それはすべて大丈夫だった - そして私は私がコマンドを実行し、これが出力され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]j/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ファイルを開くと、我々は最終的に我々の問題の行を見ることができます:なぜuser.confirmは

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 

です!見つけられない?それは基本的なDeviseパッケージの一部ではありませんか?単純であることをcreate_admin_serviceに

user.confirm! 

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 

答えて

1

が、私はラインを変更しようとすることを決めた。参考のために、これは私のユーザモデルである

user.confirm 

ための工夫のconfirmable.rb 「確認する」とは思われません。方法として。これによりdb:resetが成功したので、私はこれがdevise-rails作者の確認可能な例の問題だと仮定することができます!私は彼らのギターに適切な問題を作りました。

関連する問題