What is the correct path for text_field in my view?

Hail Caesars!

I have the following text entry field in my view: <%=
text_field :order, :company_name %>

However, company_name doesn’t really reside in the orders table. It
resides in the “company” table, which belongs to order, as follows:
Order.company.company_name. This is where my controller method
correctly saves it to. I added the company_name field to my orders
table as a temporary measure so I wouldn’t get a method not found
error. Companies belong to orders and each order has one company.

How can I change “:company_name” in my text_field helper to correctly
reflect the correct relationship between Orders and companies (that
is, Order.company.company_name instead of order[company_name] )?

Companies belonging to orders, rather than orders belonging to
companies, is correct for the business logic of this application.

Thanks in advance for your help.

Take a look at fields_for:

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M001605

Also it’s worth looking at the rails casts on advanced forms:

http://railscasts.com/episodes/73-complex-forms-part-1

This might be useful too:

http://stackoverflow.com/questions/1313149/getting-fields-for-and-accepts-nested-attributes-for-to-work-with-a-belongs-to-re

Kind Regards
Luke

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs