Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trait not registred: attribute name

Having trouble getting this done. I am using seed.rb + factory_girl to populate database with rake db:seed.

(I know that fixtures exists, but I want to get this done this way, this is just an example, the DB will be populated with complex association objects.)

My seed.rb:

require 'factory_girl_rails'
["QM","CDC","SI","QS"].each do |n|
  FactoryGirl.create(:grau, nome: n)
end

and my /factories/graus.rb

FactoryGirl.define do
  factory :grau do
    nome
  end
end

but when I run:

rake db:seed

I get:

rake aborted!
Trait not registered: nome

Tasks: TOP => db:seed

Any hints?

like image 250
iGallina Avatar asked Aug 10 '12 14:08

iGallina


1 Answers

You need to add some default value for nome:

FactoryGirl.define do
  factory :grau do
    nome 'lorem'
  end
end
like image 197
Julio Protzek Avatar answered Oct 02 '22 14:10

Julio Protzek