Wim Van Dijck
2010-Mar-25  09:40 UTC
auto_complete: if no results returned, what gets submitted?
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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Lasse Bunk
2010-Mar-26  17:28 UTC
Re: auto_complete: if no results returned, what gets submitted?
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 Dijck <google-gKMk+OYP0k+zQB+pC5nmwQ@public.gmane.org>
> 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
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Wim Van Dijck
2010-Mar-30  09:29 UTC
Re: auto_complete: if no results returned, what gets submitted?
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
% 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/
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]
In the first block, the name is still there (tester), but in the
second, it isn''t. Why would that be?
Many thanks,
Wim
On Mar 26, 7:28 pm, Lasse Bunk
<lasseb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> 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 Dijck
<goo...-gKMk+OYP0k+zQB+pC5nmwQ@public.gmane.org>
>
>
>
> > 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
>
> > --
> > You received this message because you are subscribed to the Google
Groups
> > "Ruby on Rails: Talk" group.
> > To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> > To unsubscribe from this group, send email to
> >
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscrib
e@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rubyonrails-talk?hl=en.
-- 
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Lasse Bunk
2010-Mar-30  19:25 UTC
Re: Re: auto_complete: if no results returned, what gets submitted?
Strange... What is the code you use to implement the autocomplete in the view? /Lasse 2010/3/30 Wim Van Dijck <google-gKMk+OYP0k+zQB+pC5nmwQ@public.gmane.org>> 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 > % 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/ > 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] > > In the first block, the name is still there (tester), but in the > second, it isn''t. Why would that be? > > Many thanks, > Wim > > On Mar 26, 7:28 pm, Lasse Bunk <lasseb...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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 Dijck <goo...-gKMk+OYP0k+zQB+pC5nmwQ@public.gmane.org> > > > > > > > > > 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 > > > > > -- > > > You received this message because you are subscribed to the Google > Groups > > > "Ruby on Rails: Talk" group. > > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh4Ykp1iOSErHA@public.gmane.orgm > . > > > To unsubscribe from this group, send email to > > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org><rubyonrails-talk%2Bunsubscrib > e@googlegroups.com> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.