Hi,
Extract from APRESS book...pg 218
===============================================================Listing 7-16.
Adding the auto_complete_for helper in app/controllers/
events_controller.rb
class EventsController < ApplicationController
before_filter :authenticate, :except => [:index, :show]
auto_complete_for :event, :location
#...
end
This piece of code will tell the controller to return a list of the
existing locations in the
database.
By default, auto_complete_for limits the number of returned records to
10 and orders
the query by the field being searched. As always, those are sensible
defaults; however, if
you need to overwrite them, just specify them in the hash passed to
auto_complete_for, as
follows:
auto_complete_for :event, :location, :limit => 25, :order =>
''title
DESC''
On the template side, we need to make an adjustment to how we''re
dealing with
the location field. Fortunately, this is easy.
Simply replace the following lines in app/
views/events/_form.rhtml:
<p><label
for="event_location">Location</label><br/>
<%= text_field ''event'', ''location''
%></p>
with the lines shown in Listing 7-17.
Listing 7-17. Updating app/views/events/_form to Use Auto-Completion
<p><label
for="event_location">Location</label><br/>
<%= text_field_with_auto_complete :event, :location %></p>
The code is slim, and the result is quite pleasing. As you can see in
Figure 7-7, as soon
as you start to type the location, the auto_complete_for helper runs a
database search to
find existing values for the Location field that match what you''re
typing. If you see the
location you want to enter, you can select it (with the mouse or
keyboard). If you don''t
see the location, you can ignore the suggested values and keep typing.
==============================================================On Mar 5, 9:21 am,
"dino d." <dinodorr...-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>
wrote:> Hi-
>
> I am trying to understand how auto_complete works. The docs don''t
> tell me what each parameter is, they all assume I know what they are.
> All I want to do is have a form that contains news stories that you
> can tag, with the tag suggestions coming from the tags table.
>
> In one example (http://agilewebdevelopment.com/plugins/auto_complete
> ) he says:
>
> > # Controller
> >class BlogController < ApplicationController
> >auto_complete_for :post, :title
> >end
>
> ># View
> ><%= text_field_with_auto_complete :post, title %>
>
> Here, you have the controller class, Blog, and post, and title. What
> are these? Is post the name of an existing object? Is title the
> field of a class?
>
> In another example
(http://trix.pl/blog/ruby-on-rails/auto-complete-for-rails-2-0-tutorial
> ) , he says:
>
> >class DomainsController < ApplicationController
>
> >auto_complete_for :domain, :name
>
> here, the controller name is the same as the first param of the
> method.
>
> It''s all so confusing.
>
> Anyway, can someone break down what the parameters mean?
>
> My situation specifically is, I have a stories table, a storytags
> table and a tags table. I want the user to be able to add a tag to a
> story on a form, using autocomplete for a field in a table that''s
not
> the same as the primary table (stories).
>
> If anyone can give me a push in the right direction, I''d
appreciate
> it.
>
> Thanks,
> Dino
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---