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.
Pat M. (Guest)
on 2006-01-17 02: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
Wilson B. (Guest)
on 2006-01-17 04:07
(Received via mailing list)
On 1/16/06, Pat M. <removed_email_address@domain.invalid> 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.