# Text\_field\_with\_auto\_complete doesn|t work in edit/show view

**URL:** <https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806>\
**Category:** Rails\
**Created:** [June 19, 2006, 3:22pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806 "2006-06-19T15:22:41Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 3:22pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/1 "2006-06-19T15:22:41Z")

</div>

Hi,

I am using the autocomplete for text field with ‘Scriptaculous’ and it  
works perfectly fine in “new” action.

All the examples I see are only for the “new” action.

But doesn’t default to the selected value/text in “edit/show” action? Is  
this possible or should I write custom code for “edit/show” action?

Thanks, Hari

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 3:50pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/2 "2006-06-19T15:50:34Z")

</div>

On Monday, June 19, 2006, at 3:22 PM, Nara H. wrote:

> Thanks, Hari
> 
> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

I’ve used it recently for edit views as well as new views with no  
issues.

\_Kevin

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/3 "2006-06-19T16:11:29Z")

</div>

Nara H. wrote:

> My code in “\_form.html” looks like:
> 
> Reseller Location  
> \<%= text\_field\_with\_auto\_complete :state, :state\_name, {:size =\> 50} %\>
> 
> and in controller:  
> auto\_complete\_for :state, :state\_name

Is the field on state called ‘state\_name’ or ‘name’ ?

Alan

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 4:03pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/4 "2006-06-19T16:03:22Z")

</div>

Kevin O. wrote:

Hi Kevin,

Thanks for the reply.

My code in “\_form.html” looks like:

Reseller Location  
\<%= text\_field\_with\_auto\_complete :state, :state\_name, {:size =\> 50} %\>

and in controller:  
auto\_complete\_for :state, :state\_name

In my ‘reseller’ model I have an ID for the state and the ID is to be  
looked up from the “state” model.

This code works fine in “new” action but doesn’t get the default state  
name in edit/show action?

How does your model look like? Is the usage any different?

Thanks,Hari

> On Monday, June 19, 2006, at 3:22 PM, Nara H. wrote:
> 
> > Thanks, Hari
> > 
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> I’ve used it recently for edit views as well as new views with no  
> issues.
> 
> \_Kevin

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 4:47pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/5 "2006-06-19T16:47:01Z")

</div>

Nara H. wrote:

> state\_name
> 
> \_Hari

It could be that somethings getting confused there as, ISTR, the form  
field names use underscores to separate the object and field.

How hard (or easy) would it be for you to rename the column as ‘name’ or  
‘statename’ and retry ? Would there be much code to change ?

Note this is all supposition, so if it’s a lot of work, don’t do it as  
I’ve zero guarantee of success 🙂

Alan

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 4:22pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/6 "2006-06-19T16:22:59Z")

</div>

state\_name

\_Hari

Alan F. wrote:

> Nara H. wrote:
> 
> > My code in “\_form.html” looks like:
> > 
> > Reseller Location  
> > \<%= text\_field\_with\_auto\_complete :state, :state\_name, {:size =\> 50} %\>
> > 
> > and in controller:  
> > auto\_complete\_for :state, :state\_name
> 
> Is the field on state called ‘state\_name’ or ‘name’ ?
> 
> Alan

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 5:11pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/7 "2006-06-19T17:11:16Z")

</div>

It was not a big deal to change the column name, but I still couldn’t  
get it working in show/edit view.

How does your model & code for “\_form.rhtml” looks like?

Thanks.

\_Hari

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 7:09pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/8 "2006-06-19T19:09:36Z")

</div>

On Monday, June 19, 2006, at 4:03 PM, Nara H. wrote:

> Thanks,Hari

What do you get when you do this…

\<%= debug(@state) %\>  
in your \_form.rhtml file

and call it with the ‘new’ or ‘show’ actions?

\_Kevin

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/9 "2006-06-19T22:46:26Z")

</div>

Kevin O. wrote:

> On Monday, June 19, 2006, at 4:03 PM, Nara H. wrote:
> 
> What do you get when you do this…
> 
> \<%= debug(@state) %\>  
> in your \_form.rhtml file
> 
> and call it with the ‘new’ or ‘show’ actions?
> 
> \_Kevin

When I add the debug statement I get nothing, only “—”. What  
information should this bring…even in “new” it shows only the hyphens.

\_Hari

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 19, 2006, 5:32pm UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/10 "2006-06-19T17:32:59Z")

</div>

Nara H. wrote:

> It was not a big deal to change the column name, but I still couldn’t  
> get it working in show/edit view.
> 
> How does your model & code for “\_form.rhtml” looks like?
> 
> Thanks.
> 
> \_Hari

Sorry Hari,

I don’t have one, I’m working from memory while here at my (Java) day  
job.

A.

---

<div class="post-metadata">

**Author:** ![hariraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/4491bb/32.png) [@hariraj](https://www.ruby-forum.com/u/hariraj)\
**Post date:** [June 20, 2006, 12:35am UTC](https://www.ruby-forum.com/t/text-field-with-auto-complete-doesn-t-work-in-edit-show-view/63806/11 "2006-06-20T00:35:52Z")

</div>

On Monday, June 19, 2006, at 10:46 PM, Nara H. wrote:

> > 
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Your @state variable is probably not being set properly by the  
controller. This would explain why the autocomplete is failing.

load a default or create a blank one.

\_Kevin
