two problems with auto_complete. i have user table with id fname, lname, following the steps on the wiki, drop down works but selected item does not appear in text box (issue #1) i am searching only on fname but the drop down actually shows the full name by joining fname + " " + lname i would also like it to return the user_id which is what i really need to save in the db. why is the selected answer not showing up and how i can get the id as well def auto_complete_for_user_fname auto_complete_responder_for_member params[:user][:fname] end def auto_complete_responder_for_member(value) @members = User.find...... render :partial => ''member_search'' end _member_search simply loops through @members thanks --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You may want to look at this: http://railscasts.com/episodes/102 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
yes, i looked at it and got even more confused because it was doing an associate On Apr 22, 5:39 pm, Andrew Skegg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> You may want to look at this:http://railscasts.com/episodes/102 > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
the simple auto complete works in regards to name appearing in text field, but not the customized. i thought this might be a css issue, but i have ruled that out as well. # view Just a little test: <%= text_field_with_auto_complete :user, :lname %> # controller auto_complete_for :user, :name On Apr 22, 5:45 pm, rushnosh <rashan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> yes, i looked at it and got even more confused because it was doing an > associate > > On Apr 22, 5:39 pm, Andrew Skegg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > You may want to look at this:http://railscasts.com/episodes/102 > > -- > > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
view: <%= text_field_with_auto_complete :user, :id %> controller: def auto_complete_for_user_id @users = User.find(:all, :conditions => [ ''LOWER(f_name) LIKE ?'', ''%''+params[:user][:f_name]downcase+''%'' ], :order => ''f_name asc'') render :partial => ''auto'' end partial _auto.html.erb: <ul class="users"> <% for u in @users do -%> <li class="user"><%=h u.id %><span class="informal"> (<%=h u.f_name%>)</span></li> <% end -%> </ul> this should get a drop down menu of first names that puts the id in the text field rushnosh wrote:> yes, i looked at it and got even more confused because it was doing an > associate > > On Apr 22, 5:39�pm, Andrew Skegg <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
sorry, params[:user][:f_name].downcase -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
nope, that one doesn''t even display a drop down. On Apr 22, 6:05 pm, Sn Sc <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> sorry, params[:user][:f_name].downcase > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
here is my code from firefox. why does it say autocomplete off, is this the issue? <input id="user_fname" type="text" size="30" name="user[fname]" autocomplete="off"/> <script type="text/javascript"> 1 2//<![CDATA[ 3var user_lname_auto_completer = new Ajax.Autocompleter(''user_lname'', ''user_lname_auto_complete'', ''/user/auto_complete_for_user_lname/id'', {}) 4//]]> 5 </script> <h1>Members</h1> <input id="user_fname" type="text" size="30" name="user[fname]" autocomplete="off"/> <div id="user_fname_auto_complete" class="auto_complete" style="position: absolute; left: 381px; top: 233px; width: 251px; display: none;"> <ul class="member_drop"> <li class="member_drop"> </li> <li class="member_drop selected"> </li> <li class="member_drop"> </li> <li class="member_drop"> </li> <li class="member_drop"> </li> <li class="member_drop"> </li> <li class="member_drop"> </li> <li class="member_drop"> </li> <li class="member_drop"> </li> <li class="member_drop"> </li> </ul> </div> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
no, that''s not the issue -- autocomplete off just tells the browser not to try to autocomplete the form nothing''s appearing because you don''t have any data. make sure your database query works and it''s populating the partial correctly. your ul class should be <ul class="members"> with each li being <li class="member">[name here]</li> or something similar to that format. also you should probably make sure you have skip_before_filter :verify_authenticity_token, :only=>:auto_complete_for_user_id or whatnot there as well rushnosh wrote:> here is my code from firefox. why does it say autocomplete off, is > this the issue? > > <input id="user_fname" type="text" size="30" name="user[fname]" > autocomplete="off"/> > > <script type="text/javascript"> > 1 > 2//<![CDATA[ > 3var user_lname_auto_completer = new Ajax.Autocompleter(''user_lname'', > ''user_lname_auto_complete'', ''/user/auto_complete_for_user_lname/id'', > {}) > 4//]]> > 5 > </script> > <h1>Members</h1> > <input id="user_fname" type="text" size="30" name="user[fname]" > autocomplete="off"/> > <div id="user_fname_auto_complete" class="auto_complete" > style="position: absolute; left: 381px; top: 233px; width: 251px; > display: none;"> > <ul class="member_drop"> > <li class="member_drop"> > </li> > <li class="member_drop selected"> > </li> > <li class="member_drop"> > </li> > <li class="member_drop"> > </li> > <li class="member_drop"> > </li> > <li class="member_drop"> > </li> > <li class="member_drop"> > </li> > <li class="member_drop"> > </li> > <li class="member_drop"> > </li> > <li class="member_drop"> > </li> > </ul> > </div>-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
there was data, because the drop down was working, it was just not selecting the name. not sure if anyone else has come across this. i was comparing the the two auto completes in firfox with firebug and i noticed in the simple auto complete post response from ajax was coming back all compacted (no spaces). the complicated auto_response had all the correct information but there were a lot of spaces. so i deleted all the tabs and spacing from the partial, and it fixed the problem. i also noticed <%=h which i haven''t come across before. so that issue #1 i really need help with issue #2 i get the full name in the field, but i also want to get the id, even in another field. i would really appreciate a solution here. thanks. if i am not explaining my self please ask and i will repost. On Apr 22, 8:20 pm, "s. \\" <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> no, that''s not the issue -- autocomplete off just tells the browser not > to try to autocomplete the form > > nothing''s appearing because you don''t have any data. make sure your > database query works and it''s populating the partial correctly. your ul > class should be <ul class="members"> with each li being <li > class="member">[name here]</li> or something similar to that format. > > also you should probably make sure you have skip_before_filter > :verify_authenticity_token, :only=>:auto_complete_for_user_id or whatnot > there as well > > > > rushnosh wrote: > > here is my code from firefox. why does it say autocomplete off, is > > this the issue? > > > <input id="user_fname" type="text" size="30" name="user[fname]" > > autocomplete="off"/> > > > <script type="text/javascript"> > > 1 > > 2//<![CDATA[ > > 3var user_lname_auto_completer = new Ajax.Autocompleter(''user_lname'', > > ''user_lname_auto_complete'', ''/user/auto_complete_for_user_lname/id'', > > {}) > > 4//]]> > > 5 > > </script> > > <h1>Members</h1> > > <input id="user_fname" type="text" size="30" name="user[fname]" > > autocomplete="off"/> > > <div id="user_fname_auto_complete" class="auto_complete" > > style="position: absolute; left: 381px; top: 233px; width: 251px; > > display: none;"> > > <ul class="member_drop"> > > <li class="member_drop"> > > </li> > > <li class="member_drop selected"> > > </li> > > <li class="member_drop"> > > </li> > > <li class="member_drop"> > > </li> > > <li class="member_drop"> > > </li> > > <li class="member_drop"> > > </li> > > <li class="member_drop"> > > </li> > > <li class="member_drop"> > > </li> > > <li class="member_drop"> > > </li> > > <li class="member_drop"> > > </li> > > </ul> > > </div> > > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 23, 2008, at 1:16 , rushnosh wrote:> i would also like it to return the user_id which is what i really need > to save in the db.Have a look at model_auto_completer: http://agilewebdevelopment.com/plugins/model_auto_completer -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
@xavier, i hope i can get this to work. plugin is installed, server restarted. i read thru your docs.here is the error undefined method `text_field_with_model_auto_completer'' for #<ActionView::Base:0x230968c> <%= text_field_with_model_auto_completer :user, :fname, :id, :my_id %> On Apr 23, 12:32 am, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Apr 23, 2008, at 1:16 ,rushnoshwrote: > > > i would also like it to return the user_id which is what i really need > > to save in the db. > > Have a look at model_auto_completer: > > http://agilewebdevelopment.com/plugins/model_auto_completer > > -- fxn--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
undefined method `reflect_on_association'' for NilClass:Class i saw another example and tried but got the error above: <%= belongs_to_auto_completer :user, :fname, :id %> is this suppose to create the text field? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Apr 23, 2008, at 13:40 , rushnosh wrote:> @xavier, i hope i can get this to work. > plugin is installed, server restarted. > > i read thru your docs.here is the error > > undefined method `text_field_with_model_auto_completer'' for > #<ActionView::Base:0x230968c> > > <%= text_field_with_model_auto_completer :user, :fname, :id, :my_id %>Hi, the plugin does not define such helper, note that the docs are here: http://model-ac.rubyforge.org/classes/ModelAutoCompleterHelper.html You normally use belongs_to_auto_completer. -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Apr 23, 2008, at 13:59 , rushnosh wrote:> undefined method `reflect_on_association'' for NilClass:Class > > i saw another example and tried but got the error above: > > <%= belongs_to_auto_completer :user, :fname, :id %> > is this suppose to create the text field?Does that text field live in a form about a different model? Some model you dealing with that has a user_id? -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
never got it to work, i will look into later. it would be great if someone has small form code with this method, so i can look at it. it''s the easiest way to learn it but there is nothing out there, i have searched hi and low. On Apr 23, 7:45 am, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Apr 23, 2008, at 13:59 , rushnosh wrote: > > > undefined method `reflect_on_association'' for NilClass:Class > > > i saw another example and tried but got the error above: > > > <%= belongs_to_auto_completer :user, :fname, :id %> > > is this suppose to create the text field? > > Does that text field live in a form about a different model? Some > model you dealing with that has a user_id? > > -- fxn--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 23, 2008, at 20:17 , rushnosh wrote:> never got it to work, i will look into later. it would be great if > someone has small form code with this method, so i can look at it.Besides the docs themselves, you have working examples in app/views/books/index.html.erb checking out svn://rubyforge.org/var/svn/model-ac/trunk>> Does that text field live in a form about a different model? Some >> model you dealing with that has a user_id?Please, could you respond to that question? -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
@xavier i don''t have a form. i first created the auto complete with a text field, and looked at the code in firefox/firebug so i could understand it. the form i want to create is simple. user table id fname lname show all the users in the auto complete text field by full name. when a user click on a name, i want to get user_id field, either by ajax or with a submit button or with on enter.> Besides the docs themselves, you have working examples in > > app/views/books/index.html.erbnot sure on what you mean here? thanks for taking the time. On Apr 23, 11:31 am, Xavier Noria <f...-xlncskNFVEJBDgjK7y7TUQ@public.gmane.org> wrote:> On Apr 23, 2008, at 20:17 , rushnosh wrote: > > > never got it to work, i will look into later. it would be great if > > someone has small form code with this method, so i can look at it. > > Besides the docs themselves, you have working examples in > > app/views/books/index.html.erb > > checking out > > svn://rubyforge.org/var/svn/model-ac/trunk > > >> Does that text field live in a form about a different model? Some > >> model you dealing with that has a user_id? > > Please, could you respond to that question? > > -- fxn--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Apr 23, 2008, at 20:43 , rushnosh wrote:> i don''t have a form. i first created the auto complete with a text > field, and looked at the code in firefox/firebug so i could understand > it. the form i want to create is simple. > > user table > id > fname > lname > > show all the users in the auto complete text field by full name. when > a user click on a name, i want to get user_id field, either by ajax or > with a submit button or with on enter.Hmmm, if there''s no form to submit and no parent model let me suggest something that may be simpler: use Rails auto_complete plugin and put the user IDs as ids of the list items in the HTML completion list you send back. <li id="<%= user.id %>"><%=h user.name %></li> Then, in the text_field_with_auto_complete helper call configure a JavaScript callback in :after_update_element that extracts the ID of the selected user and does whatever needed with it: function(element, value) { var model_id = value.id; ... } That''s the basic technique under model_auto_completer, only it automates some additional stuff that you may not need for that simple use case. -- fxn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---