Forum: Ruby on Rails has_one relationship problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
51675fc606ae4820496ab6acc4c7d27e?d=identicon&s=25 Raja Bhatia (Guest)
on 2006-01-12 21:45
(Received via mailing list)
I was wondering if anyone could see the error in this littte application

I have two models, User and Selection

Selection is an extension of the User model

so in the User model I have a has_one :selection
and in Selection I have a belongs_to :user

in my views, i cannot get @user.selection to work but @user works fine.



http://www.rafb.net/paste/results/GSBt1e61.html

Thanks,

r.b
69b2ef4bce76b5b27c94e898976dc6d8?d=identicon&s=25 matthew clark (Guest)
on 2006-01-12 21:54
(Received via mailing list)
What you describe should be fine, so the problem must be somewhere else.
Do
you have your selection table setup with a user_id field?

matt
51675fc606ae4820496ab6acc4c7d27e?d=identicon&s=25 Raja Bhatia (Guest)
on 2006-01-12 22:25
(Received via mailing list)
yes, the selections table has a user_id field
69b2ef4bce76b5b27c94e898976dc6d8?d=identicon&s=25 matthew clark (Guest)
on 2006-01-12 23:14
(Received via mailing list)
One more thing to check is to make sure that the user actually has a
selection assigned to it.  Do this in the controller-

@user.selection = Selection.new
51675fc606ae4820496ab6acc4c7d27e?d=identicon&s=25 Raja Bhatia (Guest)
on 2006-01-13 18:16
(Received via mailing list)
is that necessary?

I was under the assumption that the model relationships would handle
the collection?
This topic is locked and can not be replied to.