# Autocomplete for

**URL:** <https://www.ruby-forum.com/t/autocomplete-for/126439>\
**Category:** Rails\
**Created:** [January 18, 2008, 9:07am UTC](https://www.ruby-forum.com/t/autocomplete-for/126439 "2008-01-18T09:07:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 18, 2008, 9:07am UTC](https://www.ruby-forum.com/t/autocomplete-for/126439/1 "2008-01-18T09:07:59Z")

</div>

I have this code in my view:

\<%= text\_field\_with\_auto\_complete :client, :name %\>

when I submit new, y get:  
“client”=\>{“name”=\>“MSO”}

I want to get:  
“repair\_ticket”=\>{“client\_id”=\>"??"}

My models are

class Client \< ActiveRecord::Base  
has\_many :repair\_tickets  
end

class RepairTicket \< ActiveRecord::Base  
belongs\_to :client  
end

How can I do that?

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 18, 2008, 9:40am UTC](https://www.ruby-forum.com/t/autocomplete-for/126439/2 "2008-01-18T09:40:45Z")

</div>

I’m not sure what you’re asking but here goes.

They submit :client =\> {:name =\> ‘john’}

you do

client = Client.find(:first, :include =\> [:repair\_tickets] :conditions  
=\> [‘name = ?’, params[:client][:name]])  
client.repair\_tickets =\> what you want?

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 18, 2008, 9:49am UTC](https://www.ruby-forum.com/t/autocomplete-for/126439/3 "2008-01-18T09:49:31Z")

</div>

John S. wrote:

> I have this code in my view:
> 
> \<%= text\_field\_with\_auto\_complete :client, :name %\>
> 
> when I submit new, y get:  
> “client”=\>{“name”=\>“MSO”}
> 
> I want to get:  
> “repair\_ticket”=\>{“client\_id”=\>"??"}

A bit of a hack, but you could do somthing like this before you save:

@repair\_ticket.client\_id = params[‘form\_field’][‘name’]
