Read more

Unsaved record disappears when assigning to an association

Tobias Kraze
September 25, 2012Software engineer at makandra GmbH

If this happens to you:

user.avatar = Avatar.new
user.avatar  # => nil
Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

(where avatar is a belongs_to), you probably declared your association incorrectly.

Always do

class User < ActiveRecord::Base
  belongs_to :avatar
end

and never

class User < ActiveRecord::Base
  belongs_to 'avatar'
end
Posted by Tobias Kraze to makandra dev (2012-09-25 14:35)