On 1/16/06, Pat Maddox <pergesu@gmail.com> wrote:> 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.
>
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''.