Código:
Cuando trato de crear un modelo para mi prueba en la consola de railsclass User < ActiveRecord::Base has_many :events has_many :participants has_many :events, through: :participants end class Event < ActiveRecord::Base belongs_to :user belongs_to :event_status has_many :participants has_many :user, through: :participants end class Participant < ActiveRecord::Base belongs_to :user belongs_to :event end FactoryGirl.define do factory :event do user event_status name { FFaker::Name.name } description { FFaker::Lorem.phrase } avatar { FFaker::Avatar.image } latitude { FFaker::Geolocation.lat } longitude { FFaker::Geolocation.lng } end end FactoryGirl.define do factory :user do first_name { FFaker::Name.first_name } last_name { FFaker::Name.last_name } phone_number { FFaker::PhoneNumber.phone_number } email { FFaker::Internet.email } handle { FFaker::Name.name } password "12345678" imei "1234567890" gender "M" end end FactoryGirl.define do factory :event_status do name { FFaker::Name.first_name } description { FFaker::Lorem.phrase } end end
Código:
Me sale el siguiente errorevent = FactoryGirl.build(:event)
Código:
Creo que el problema esta con las relaciones, estoy empezando en RoR y si me pueden guiar les agradeceria muchisimo NoMethodError: undefined method `each' for #<User:0x007fb6338b2a40> from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activemodel-4.2.3/lib/active_model/attribute_methods.rb:433:in `method_missing' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/associations/collection_association.rb:365:in `replace' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/associations/collection_association.rb:47:in `writer' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activerecord-4.2.3/lib/active_record/associations/builder/association.rb:123:in `user=' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:16:in `public_send' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:16:in `block (2 levels) in object' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:15:in `each' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:15:in `block in object' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:14:in `tap' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/attribute_assigner.rb:14:in `object' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/evaluation.rb:12:in `object' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/strategy/build.rb:9:in `result' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/factory.rb:42:in `run' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/factory_runner.rb:23:in `block in run' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.3/lib/active_support/notifications.rb:166:in `instrument' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/factory_runner.rb:22:in `run' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/factory_girl-4.5.0/lib/factory_girl/strategy_syntax_method_registrar.rb:20:in `block in define_singular_strategy_method' from (irb):2 from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/console.rb:110:in `start' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/console.rb:9:in `start' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:68:in `console' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands/commands_tasks.rb:39:in `run_command!' from /Users/german/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.3/lib/rails/commands.rb:17:in `<top (required)>' from bin/rails:4:in `require' from bin/rails:4:in `<main>'irb(main):003:0>