I''m having a little trouble trying to understand how autocomplete works. This is namely because there are so many plugins out there and some are outdated and many come with mixed instructions. I''m using the standard plugin called auto_complete from David Heinemeier Hansson. Here''s what I have so far: Teams controller auto_complete_for :team, :name def virtual_matchups @teams = Team.find(:all, :conditions => [''name LIKE ?'', "%#{params[:search]}%"]) end Created a custom method called virtual_matchups. The name of the model is Team and the name of the team name field is name. I created a custom view: virtual_matchups.html.erb <br><br> <h1> Test Virtual Matchups </h1> <%= text_field_with_auto_complete :team, :name %> I added the following to routes.rb: map.auto_complete '':controller/:action'', :requirements => { :action => /auto_complete_for_\S+/ }, :conditions => { :method => :get } .. I go to http://localhost:3000/teams/virtual_matchups .. I get: Couldn''t find Team with ID=virtual_matchups I go to http://localhost:3000/teams/virtual_matchups/1 .. I get: the text field box but when typing into it, it does nothing... I could use some help with a step by step procedure on how to use auto complete. If I can do it just one time, I''m sure I could figure it out. However, I''ve been messing around with the regular version, a jquery version, even the ryan bates railscast and "none of them" work.... However, all start right in the middle of something and never explain how to use it step by step from the beginning. I can''t find a solid tutorial on using the plugin. Thanks. -- Posted via http://www.ruby-forum.com/.
Älphä Blüë
2009-Jul-24 04:59 UTC
Re: Plugin auto_complete - unable to get it to work at all.
I believe I found a partial answer: In my teams controller I placed: class TeamsController < ApplicationController skip_before_filter :verify_authenticity_token, :only => [:auto_complete_for_team_name] def auto_complete_for_team_name() team_name = params[:team][:name] @teams = Team.find(:all, :conditions => [''name LIKE ?'', "%" + team_name + "%"]) render :partial => ''teamname'' end def virtual_matchups end In my virtual_matchups.html.erb file I placed as a test: <h1> Test Virtual Matchups </h1> <%= text_field_with_auto_complete :team, :name ,{}, :skip_style => false %> I created a partial for teamname: <ul> <% for team in @teams do %> <li> <div> <%=h team.name %> </div> </li> <% end %> </ul> In my routing file I placed: map.virtual_matchups ''/virtual_matchups'', :controller => ''teams'', :action => ''virtual_matchups'' I restarted the server and the autocomplete works for this page, but I haven''t tried it with a form. My thoughts on this are it was very cumbersome to get it to work. I had to go through several different sites, put together all the pieces of the puzzle before it finally worked. I have no idea why I had to use the skip_before_filter but without it, it would not autocomplete. Can someone please look over the fixes I provided and if you have knowledge of autocomplete let me know if there is a simpler way of getting it to work, and/or what I need to do to polish up the code I created thus far to get it to work? I will need two fields and a submit button that performs a query to the same controller but to a different action that will render a completely different partial containing information. Many thanks in advance. -- Posted via http://www.ruby-forum.com/.
my guess: auto_complete_for_team_name is called through ajax and the ajax call does not provide (bring along) any authenticity_token... On Jul 24, 6:59 am, "Älphä Blüë" <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt> wrote:> I believe I found a partial answer: > > In my teams controller I placed: > > class TeamsController < ApplicationController > skip_before_filter :verify_authenticity_token, :only => > [:auto_complete_for_team_name] > > def auto_complete_for_team_name() > team_name = params[:team][:name] > @teams = Team.find(:all, :conditions => [''name LIKE ?'', "%" + > team_name + "%"]) > render :partial => ''teamname'' > end > > def virtual_matchups > end > > In my virtual_matchups.html.erb file I placed as a test: > > <h1> Test Virtual Matchups </h1> > <%= text_field_with_auto_complete :team, :name ,{}, :skip_style => false > %> > > I created a partial for teamname: > > <ul> > <% for team in @teams do %> > <li> > <div> > <%=h team.name %> > </div> > </li> > <% end %> > </ul> > > In my routing file I placed: > > map.virtual_matchups ''/virtual_matchups'', :controller => ''teams'', > :action => ''virtual_matchups'' > > I restarted the server and the autocomplete works for this page, but I > haven''t tried it with a form. > > My thoughts on this are it was very cumbersome to get it to work. I had > to go through several different sites, put together all the pieces of > the puzzle before it finally worked. > > I have no idea why I had to use the skip_before_filter but without it, > it would not autocomplete. > > Can someone please look over the fixes I provided and if you have > knowledge of autocomplete let me know if there is a simpler way of > getting it to work, and/or what I need to do to polish up the code I > created thus far to get it to work? > > I will need two fields and a submit button that performs a query to the > same controller but to a different action that will render a completely > different partial containing information. > > Many thanks in advance. > > -- > Posted viahttp://www.ruby-forum.com/.
links which substantiate my guess ;-) http://ryandaigle.com/articles/2007/9/24/what-s-new-in-edge-rails-better-cross-site-request-forging-prevention http://henrik.nyh.se/2008/05/rails-authenticity-token-with-jquery On Jul 24, 7:45 am, clemens <clemens.w...-OI3hZJvNYWs@public.gmane.org> wrote:> my guess: > auto_complete_for_team_name is called through ajax and the ajax call > does not provide (bring along) any authenticity_token... > > On Jul 24, 6:59 am, "Älphä Blüë" <rails-mailing-l...@andreas-s.net> > wrote: > > > > > I believe I found a partial answer: > > > In my teams controller I placed: > > > class TeamsController < ApplicationController > > skip_before_filter :verify_authenticity_token, :only => > > [:auto_complete_for_team_name] > > > def auto_complete_for_team_name() > > team_name = params[:team][:name] > > @teams = Team.find(:all, :conditions => [''name LIKE ?'', "%" + > > team_name + "%"]) > > render :partial => ''teamname'' > > end > > > def virtual_matchups > > end > > > In my virtual_matchups.html.erb file I placed as a test: > > > <h1> Test Virtual Matchups </h1> > > <%= text_field_with_auto_complete :team, :name ,{}, :skip_style => false > > %> > > > I created a partial for teamname: > > > <ul> > > <% for team in @teams do %> > > <li> > > <div> > > <%=h team.name %> > > </div> > > </li> > > <% end %> > > </ul> > > > In my routing file I placed: > > > map.virtual_matchups ''/virtual_matchups'', :controller => ''teams'', > > :action => ''virtual_matchups'' > > > I restarted the server and the autocomplete works for this page, but I > > haven''t tried it with a form. > > > My thoughts on this are it was very cumbersome to get it to work. I had > > to go through several different sites, put together all the pieces of > > the puzzle before it finally worked. > > > I have no idea why I had to use the skip_before_filter but without it, > > it would not autocomplete. > > > Can someone please look over the fixes I provided and if you have > > knowledge of autocomplete let me know if there is a simpler way of > > getting it to work, and/or what I need to do to polish up the code I > > created thus far to get it to work? > > > I will need two fields and a submit button that performs a query to the > > same controller but to a different action that will render a completely > > different partial containing information. > > > Many thanks in advance. > > > -- > > Posted viahttp://www.ruby-forum.com/.- Hide quoted text - > > - Show quoted text -
Alpha Blue
2009-Jul-24 13:02 UTC
Re: Plugin auto_complete - unable to get it to work at all.
Thanks Clemens. Well I will continue to use the skip_before_filter with the only statement against that particular method then. This seems the easiest implementation as my search results finds a lot more problems doing other things... -- Posted via http://www.ruby-forum.com/.