In my application, I have 2 classes:
class City < ActiveRecord::Base
has_many :events
end
class Event < ActiveRecord::Base
belongs_to :city
attr_accessible :title, :city_id
end
If I create a city object:
city = City.create!(:name => 'My city')
and then pass parameters to create such an event:
event = Event.create!(:name => 'Some event', :city => city)
I get
event.city_id => null
So the question is, is it possible to pass parameters in such a way as to link my objects, what am I doing wrong? Or should I use other ways (e.g.
event.city = city
)
source
share