Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "undefined method `assert_valid_keys`"?

Tags:

Any idea why I am getting this error:

Exception encountered: #<NoMethodError: undefined method `assert_valid_keys' for :widget:Symbol> 

when I try to do a Factory.build(:widget) on the following model:

class Widget < ActiveRecord::Base   belongs_to :designer, :vendor   # ... end 

When I remove the belongs_to line the error goes away.

like image 958
bjnord Avatar asked Feb 29 '12 22:02

bjnord


People also ask

What is an undefined method?

A method or statement also returns undefined if the variable that is being evaluated does not have an assigned value. A function returns undefined if a value was not returned .

What does undefined method mean in Ruby?

This is a common Ruby error which indicates that the method or attribute for an object you are trying to call on an object has not been defined.


1 Answers

 belongs_to :designer, :vendor 

won't work. :vendor is treated like an option. And, of course, there isn't such an option. See docs for further information.

If you need two belongs_to relations, just change your code to:

 belongs_to :designer  belongs_to :vendor 
like image 120
lucapette Avatar answered Nov 18 '22 20:11

lucapette