Dave Perrett

Undefined Method Assert_valid_keys in Rails

database, programming, quickie, rails, ruby, web

If you are getting an error about ‘undefined method assert_valid_keys’ in Rails :

1
undefined method `assert_valid_keys' for :time_entry_product:Symbol

… it may be because you have two relationships specified on the same line in your model :

1
2
3
class TimeEntry < ActiveRecord::Base
  belongs_to :time_entry_category, :time_entry_product
end

If you change this so that the relationships are on separate lines, the problem usually goes away :

1
2
3
4
class TimeEntry < ActiveRecord::Base
  belongs_to :time_entry_category
  belongs_to :time_entry_product
end