# Auto\_complete with has\_one association

**URL:** <https://www.ruby-forum.com/t/auto-complete-with-has-one-association/188078>\
**Category:** Rails\
**Created:** [May 5, 2010, 11:43am UTC](https://www.ruby-forum.com/t/auto-complete-with-has-one-association/188078 "2010-05-05T11:43:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [May 5, 2010, 11:43am UTC](https://www.ruby-forum.com/t/auto-complete-with-has-one-association/188078/1 "2010-05-05T11:43:03Z")

</div>

Hi,  
Have an issue with the rails auto complete, it works fine but I don’t  
know how to find the id element search in the textfield.

Here is what I’ve done:  
\<%= text\_field\_with\_auto\_complete :user, :ville\_name, { :size =\> 15 },  
{ :url =\> formatted\_villes\_path(:js), :method =\> :get, :param\_name =\>  
‘search’ } %\>

Model:  
class User \< ActiveRecord::Base  
attr\_accessible :email, :ville\_id, :newsletters, :role, :gender,  
:first\_name, :last\_name, :birth\_date  
serialize :newsletters

has\_one :ville

GENDERS = %w(Homme Femme)  
ROLES = %w(Admin Business User)

def full\_name  
[@first\_name, @last\_name].join(’ ')  
end

def ville\_name  
ville.name if ville  
end

def ville\_name=(name)  
self.ville = Ville.find\_or\_create\_by\_name(name) unless name.blank?  
end

end

I want to find the “ville” ID typed in the auto complete field.

Greg
