I think I’m missing something easy here… but can’t figure it out.
class User < ActiveRecord::Base
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
has_many :events
end
class Event < ActiveRecord::Base
attr_accessible :start, :end, :all_day, :url
belongs_to :user
end
u1 = User.create name: "Bob", email: "bob@what.com", password: "asdfasdf"
u1.create_event(start: 3.days.from_now)
–>
undefined method `create_event' for #<User:0x007f918cbbf7b8>
However,
u1.events << Event.create!(start: 3.days.from_now)
works!
Don’t see create_event defined on User. You can also use
Fascinated to see that
works. Although, I do think it is a bit obtuse and may not be immediately clear to a casual reader of the code.