LoginSignup
3
2

More than 3 years have passed since last update.

rails c で急にエラーが出た時

Last updated at Posted at 2020-07-21

以前FactoryBotの確認でコンソールをいじっている時にそれは起こった。

irb(main):001:0> FactoryBot.create(:user)
Traceback (most recent call last):
        1: from (irb):1
KeyError (Factory not registered: "user")

FactoryBotの中身を確認してみる。。

FactoryBot.define do
  factory :user do
    name {Faker::Name.last_name}
    email {Faker::Internet.free_email}
    password = Faker::Internet.password(min_length: 8)
    password {password}
    password_confirmation {password}
  end
end

FavtoryBotのエラーについて調べたが()で閉じることでエラーが出ることが多いみたい。でも{}で中身入れてるし問題ない。

調べていくうちにrailsコマンドが正常に作動しない時はspringを止めたら動き始めるとのことが発覚。

springはrailsが持っている機能で入力したrailsコマンドの起動を早くしてくれるらしいがたまに固まってしまうらしい。

spring stop

これで無事動き始めました。

安心してください、、、またrailsコマンドを使うと自動的にspringは起き上がります!

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2