ruby on rails - Undefined method `relations` when assigning belongs to association -


i have 2 models:

class annotation   include mongoid::document   belongs_to :event   field :desc, type: string end  class event::event   include mongoid::document   has_many :annotations end 

and created 2 objects in rails console typing:

a = annotation.new e = event::event.new 

now everythings good, when do

a.event = e 

i following error:

nomethoderror: undefined method `relations' event:module 

why error happening , how fix it? thanks.

try this:

class annotation   include mongoid::document   belongs_to :event, class_name: 'event::event'   ... end 

the belongs_to association default assumes associated object of type event, event module. class name here should event::event. so, needs specified in relation.

let me know if helps.


Comments