# What is the correct path for text\_field in my view?

**URL:** <https://www.ruby-forum.com/t/what-is-the-correct-path-for-text-field-in-my-view/185485>\
**Category:** Rails\
**Created:** [March 21, 2010, 11:30am UTC](https://www.ruby-forum.com/t/what-is-the-correct-path-for-text-field-in-my-view/185485 "2010-03-21T11:30:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DrSJackanapes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@DrSJackanapes](https://www.ruby-forum.com/u/DrSJackanapes)\
**Post date:** [March 21, 2010, 11:30am UTC](https://www.ruby-forum.com/t/what-is-the-correct-path-for-text-field-in-my-view/185485/1 "2010-03-21T11:30:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DrSJackanapes](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@DrSJackanapes](https://www.ruby-forum.com/u/DrSJackanapes)\
**Post date:** [March 22, 2010, 8:22am UTC](https://www.ruby-forum.com/t/what-is-the-correct-path-for-text-field-in-my-view/185485/2 "2010-03-22T08:22:44Z")

</div>

Take a look at fields\_for:

> **[ActionView::Helpers::FormHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M001605)**
>
> Form helpers are designed to make working with resources much easier compared to using vanilla HTML.

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

> **[\#73 Complex Forms Part 1 - RailsCasts](http://railscasts.com/episodes/73-complex-forms-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

This might be useful too:

> <https://stackoverflow.com/questions/1313149/getting-fields-for-and-accepts-nested-attributes-for-to-work-with-a-belongs-to-r>

Kind Regards  
Luke
