Forum: Ruby on Rails Accessing associations in a form helper

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.
42172acdf3c6046f84d644cb0b94642c?d=identicon&s=25 Pat Maddox (pergesu)
on 2006-01-17 01:15
(Received via mailing list)
I've got two models, a Company and a User, and a Company belongs_to a
User.  When I create/edit a company object, I'd like to be able to
modify the associated user.  Can I do this directly with form helpers?
 Something like
text_field("company.user", "login")

Right now I'm having a user object and a company object, and then
associating them with @company.user = @user in my controller.  Just
wondering if I can use the association directly, or if there's some
preferred way to do this.

Pat
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-01-17 03:07
(Received via mailing list)
On 1/16/06, Pat Maddox <pergesu@gmail.com> wrote:
>
Because the helpers rely on specifically-named instance variables, you
end up having to do this:
<% @user = @company.user -%>
<%= text_field 'user', 'login' %>

Unfortunate, but there's no way to ask an object what name it was
bound to in the calling context, so Rails has to 'cheat'.
This topic is locked and can not be replied to.