# This feels ugly

**URL:** <https://www.ruby-forum.com/t/this-feels-ugly/74584>\
**Category:** Rails\
**Created:** [February 28, 2006, 7:53am UTC](https://www.ruby-forum.com/t/this-feels-ugly/74584 "2006-02-28T07:53:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [February 28, 2006, 7:53am UTC](https://www.ruby-forum.com/t/this-feels-ugly/74584/1 "2006-02-28T07:53:53Z")

</div>

i better explain a little to get started.  
in my form for creating a Person, there’s a Company field. People  
belong to companies and companies have many people.

in my person form i have:  
\<%= text\_field ‘person’, ‘Company’ %\>

in my controller i have  
def create  
params[‘person’][‘Company’] = Company.find\_by\_name(params[‘person’]  
[‘Company’])  
@person = Person.new(params[:person])  
…  
end

this seems ugly to me and makes me feel like this is not the best way.  
I’m doing this because Person.new expects Company to be a Company  
object not a string. params[‘person’][‘Company’] comes in from the  
form as “cutco” or “edgeslice” or whatever.

Anyway, i’m using a text field instead of a select box, because  
select boxes with more that like 3 items are annoying to use. I’m  
going to autocomplete the company text field.

how do people usually create new objects (and specify who they  
belong\_to) from the child’s (in this case Person) view/controller?

travis

---

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [February 28, 2006, 7:56am UTC](https://www.ruby-forum.com/t/this-feels-ugly/74584/2 "2006-02-28T07:56:57Z")

</div>

2006/2/28, travis laduke [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> in my person form i have:  
> \<%= text\_field ‘person’, ‘Company’ %\>

You can use this instead:  
\<%= text\_field\_tag ‘company’ %\>

def create  
params[:person][:company] = Company.find\_by\_name(params[:company])  
@person = Person.build(params[:person])  
if @person.save then  
…  
else  
…  
end  
end

For your question of how we do it, that is one of the ways I do it  
(auto complete and all).

Hope that helps.
