# Auto\_complete: if no results returned, what gets submitted?

**URL:** <https://www.ruby-forum.com/t/auto-complete-if-no-results-returned-what-gets-submitted/185761>\
**Category:** Rails\
**Created:** [March 25, 2010, 6:44pm UTC](https://www.ruby-forum.com/t/auto-complete-if-no-results-returned-what-gets-submitted/185761 "2010-03-25T18:44:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wim\_Van\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/4491bb/32.png) [@Wim\_Van\_D](https://www.ruby-forum.com/u/Wim_Van_D)\
**Post date:** [March 25, 2010, 6:44pm UTC](https://www.ruby-forum.com/t/auto-complete-if-no-results-returned-what-gets-submitted/185761/1 "2010-03-25T18:44:30Z")

</div>

Hi,

I’m a rails noob, tring to teach myself, so feel free to point me to  
the correct FM if need be 😉

I’m playing with the auto\_complete plugin. I have a page to manage  
expenses, and there’s field ‘supplier’ to whom the expense is paid.  
I can successfully retrieve the suppliers name from the suppliers  
table, but when I type a name that doesn’t exist yet, and submit,  
nothing gets submitted?

Can anyone shed any light to why that is?  
Ideally, in this situation, I’d like to be redirected to the supplier  
model ‘new’ page, but I can settle for it just accepting what I type?

Best regards,  
Wim

---

<div class="post-metadata">

**Author:** ![Wim\_Van\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/4491bb/32.png) [@Wim\_Van\_D](https://www.ruby-forum.com/u/Wim_Van_D)\
**Post date:** [March 26, 2010, 6:30pm UTC](https://www.ruby-forum.com/t/auto-complete-if-no-results-returned-what-gets-submitted/185761/2 "2010-03-26T18:30:17Z")

</div>

Wim,

I just tried it out, and it works fine for me â€“ if I type a name that  
doesn’t exist, then that name is submitted.

In the controller:

auto\_complete\_for :supplier, :name

In the action:

render :text =\> “Name = #{params[:supplier][:name]}”

And in the view:

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

If this doesn’t help you, maybe you could post some code?

/Lasse

2010/3/25 Wim Van D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Wim\_Van\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/4491bb/32.png) [@Wim\_Van\_D](https://www.ruby-forum.com/u/Wim_Van_D)\
**Post date:** [March 30, 2010, 9:27pm UTC](https://www.ruby-forum.com/t/auto-complete-if-no-results-returned-what-gets-submitted/185761/3 "2010-03-30T21:27:15Z")

</div>

Strange… What is the code you use to implement the autocomplete in the  
view?

/Lasse

2010/3/30 Wim Van D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Wim\_Van\_D](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/4491bb/32.png) [@Wim\_Van\_D](https://www.ruby-forum.com/u/Wim_Van_D)\
**Post date:** [March 30, 2010, 11:30am UTC](https://www.ruby-forum.com/t/auto-complete-if-no-results-returned-what-gets-submitted/185761/4 "2010-03-30T11:30:44Z")

</div>

Hi Lasse,

thanks for repying.  
I have the same for the controller and the view, not sure about the  
action.

This is how set about to get there:  
% script/generate scaffold\_for\_view supplier name:string street:string  
streetnumber:decimal   
zipcode:decimal city:string mail:string phone:string vat:string  
% rake db:migrate  
% gem sources -a [http://gemcutter.org](http://gemcutter.org)  
% sudo gem install view\_mapper  
% ./script/plugin install git://github.com/rails/auto\_complete.git  
I add to the supplier model:  
has\_many :expenses

% script/generate scaffold\_for\_view expense title:string  
amount:decimal payment:string   
description:string category:string subcategory:string date:date –  
view belongs\_to\_auto\_complete:supplier

That’s it. When I add some suppliers, I can autocomplete them in the  
expense form, but when I use a name that’s not found, it doesn’t get  
submitted.  
The output of the server script is:  
Processing ExpensesController#create (for 127.0.0.1 at 2010-03-30  
11:26:31) [POST]  
Parameters: {“commit”=\>“Create”, “expense”=\>{“date(1i)”=\>“2010”,  
“subcategory”=\>“test”, “category”=\>“test”, “date(2i)”=\>“3”,  
“title”=\>“Test”, “date(3i)”=\>“29”, “amount”=\>“0.0”, “payment”=\>“test”,  
“supplier\_name”=\>“tester”, “description”=\>“test”},  
“authenticity\_token”=\>“c845768fead94721c294f12ebc6f3b508e031398”}  
Supplier Load (0.2ms) SELECT \* FROM “suppliers” WHERE  
(“suppliers”.“name” = ‘tester’) LIMIT 1  
Rendering template within layouts/expenses  
Rendering expenses/new  
Rendered expenses/\_form (78.5ms)  
Completed in 183ms (View: 144, DB: 0) | 200 OK [[http://localhost/](http://localhost/)  
expenses]

Processing ExpensesController#create (for 127.0.0.1 at 2010-03-30  
11:26:39) [POST]  
Parameters: {“commit”=\>“Create”, “expense”=\>{“date(1i)”=\>“2010”,  
“subcategory”=\>“test”, “category”=\>“test”, “date(2i)”=\>“3”,  
“title”=\>“Test”, “date(3i)”=\>“29”, “amount”=\>“0.01”,  
“payment”=\>“test”, “supplier\_name”=\>“”, “description”=\>“test”},  
“authenticity\_token”=\>“c845768fead94721c294f12ebc6f3b508e031398”}  
Supplier Load (0.2ms) SELECT \* FROM “suppliers” WHERE  
(“suppliers”.“name” = ‘’) LIMIT 1  
Expense Create (34.4ms) INSERT INTO “expenses” (“category”,  
“subcategory”, “created\_at”, “title”, “updated\_at”, “amount”, “date”,  
“payment”, “supplier\_id”, “description”) VALUES(‘test’, ‘test’,  
‘2010-03-30 09:26:39’, ‘Test’, ‘2010-03-30 09:26:39’, 0.01,  
‘2010-03-29’, ‘test’, NULL, ‘test’)  
Redirected to #Expense:0x103d8e920  
Completed in 52ms (DB: 35) | 302 Found [[http://localhost/expenses](http://localhost/expenses)]

In the first block, the name is still there (tester), but in the  
second, it isn’t. Why would that be?

Many thanks,  
Wim
