I have a user model with has_one :designpad, a designpad model with belongs_to :user and the column user_id.
Now I do this:
u = User.first
d = Designpad.new
d.user_id = u.id
d.save
d.user # returns the user (== u)
u.designpad # always returns nil, but why?
Why does u.designpad return nil? u.methods lists the methods designpad and designpad=, just as expected while using a has_one association.
But u.designpad just won’t return the expected designpad.
As @keymone said, the problem that your
uobject is not reloaded. Also you can refactor your code a little: