Topic: Autocomplete Styling Puzzle

If you see the scriptaculous demo for autocomplete, you will see that the options list contains the avatar, person name, and email. But once the user selects an option, only the name shows up in the text box. Any ideas on how to achieve that?

Re: Autocomplete Styling Puzzle

There's a plugin by Xavier Noria which should help with this;

http://agilewebdevelopment.com/plugins/ … _completer

Also, this might be of interest, I remember it explaining a similar implementation;
http://www.slash7.com/articles/2005/8/1 … iptaculous

I didn't get the model_auto_completer working because I'm a a bit of a newbie, but if you do manage to get it working - and especially if you encounter the problem I had with the view receiving an entirely new request, rather than a partial - please let me know!

This is my post on the problem, if you're interested;
http://www.ruby-forum.com/topic/163614#new

Re: Autocomplete Styling Puzzle

I have the plugin and it worked fine the first time. Had no problems. Im completely 'duh!' about CSS so I havent got an idea how to go about styling it like the way i mentioned. I actually came across the post you've linked when i was searching around for related topics. And I had Amy hoy's post open for quite sometime but realised that i could understand most of the scriptacuolous code without the article. Will give it a thorough read to see if it covers what i need.
The post you have shown is kinda long. If you can just post your code for model_auto_completer here maybe i can help you figure out what the problem is. Am still a newbie too so no promises smile

Re: Autocomplete Styling Puzzle

yourstruly_vinay wrote:

I have the plugin and it worked fine the first time. Had no problems. Im completely 'duh!' about CSS so I havent got an idea how to go about styling it like the way i mentioned. I actually came across the post you've linked when i was searching around for related topics. And I had Amy hoy's post open for quite sometime but realised that i could understand most of the scriptacuolous code without the article. Will give it a thorough read to see if it covers what i need.
The post you have shown is kinda long. If you can just post your code for model_auto_completer here maybe i can help you figure out what the problem is. Am still a newbie too so no promises smile

Ace, thanks for the offer. I just removed all the commented code for model auto completer yesterday, so I'll set aside a time to get it back in Git and post a concise explanation of my problem here - may not be till tonight/tomorrow. Also, if you have problems with CSS, let me know & post it here, I'm much much better with CSS than I am with Rails.

Re: Autocomplete Styling Puzzle

smile The Amy Hoy post fixed that for me inadvertently. Was going through the comments section and it so happens that a div class of "informal" to data that you dont want in the text box will do the trick.

<%- for contact in @contacts do -%>
<li><%=h contact.name %>|<div class="informal"><%=h contact.email %></div></li>
<%- end -%>

Thanks for that! Waiting to see the code and help out smile

Re: Autocomplete Styling Puzzle

That's something that would've caught me out; I didn't find an explanation of the 'informal' class div and its declarations/uses when I was trying it out.

My problem with auto complete is possibly related to a problem I had with username ajax validation; http://weblogs.java.net/blog/bleonard/a … ation.html

When I make a call to a partial from a controller, instead of rendering the partial, the element (the one which is supposed to wrap the ajax-ified area) renders an entirely new <body> tag (i.e. header, main content etc) within itself. My ajax requests are going through, Firebug shows the browser making the requests. Could it be a problem with authenticity tokens? I know the js libraries are included because the ajax requests work (and they don't work when I comment out the script tags).

I would like to elaborate more but the last message in this thread pretty much sums it up;
http://www.ruby-forum.com/topic/163614#new

Re: Autocomplete Styling Puzzle

Hi Neil,
I just went through that whole thread and i was just wondering. Did you try this?

  protect_from_forgery :except => [:auto_complete_belongs_to_for_invitation_recipient_name]

Your last post seems a little confusing so im just confirming this. I have this in place and everything else is the same and its working for me. Also, just see what HTML request goes through in Firebug when you try the autocomplete.

Re: Autocomplete Styling Puzzle

Thanks, you're on the right track. I had a similar issue with an ajax validation on a user name attribute for the sign up form, and it turns out a before filter was breaking the ajax request. I haven't applied the fix to the auto complete just yet but it behaved in the same way as the first feature so I'm sure that I've found the fix (just need to implement it).  IIRC, I needed to set 'skip_before_filter :login_required'; would you expect that for an ajax only controller action? I'm worried that the user search auto complete could be hacked some how if it doesn't require a login. It's fine on my sign up form because that shouldn't :require_login anyway, but the auto_complete will exist within actions which will require_login. Any ideas on the security implications?

Re: Autocomplete Styling Puzzle

I dont think the login_required before_filter will affect your autocomplete. It will affect your signup though because obviously, the user is not logged in. I understand your security concerns. I need to look them up myself. Right now, I have it working and thats what i need.
Again, i think its just a matter of adding the above line of code to the controller along with the filters. as i understand, the protect_from_forgery method is a filter to every controller and its actions built into rails to check the Authenticity token. Ajax calls apparently do not pass through the authenticity token (take a look at the params in the development log). So u skip forgery protection for this Ajax method alone.
I would appreciate it if you put up any links that you found regarding the security issue.

Re: Autocomplete Styling Puzzle

Neil,
Are you sure you are rendering no layout with the result in the Ajax call action? Do check out the "Designing your Rails actions for Ajax" section in this page http://api.rubyonrails.org/classes/Acti … elper.html

Re: Autocomplete Styling Puzzle

yourstruly_vinay wrote:

Neil,
Are you sure you are rendering no layout with the result in the Ajax call action? Do check out the "Designing your Rails actions for Ajax" section in this page http://api.rubyonrails.org/classes/Acti … elper.html

Sorry I didn't get back to your last response, I had the auto complete on the bottom of my todo list for today so I was hoping to get back to you once it's all set-up again and I have my head round the problem. Engine Yard almost have my slice ready after signing up last week, so I've been holding back on new features. I really think it was down to one of the controller actions, though - the exact same problem was fixed by asking the user controller to skip the 'login required' before filter. It would certainly explain why the area designated for the ajax response was rendering an entirely new layout and the login form, rather than just the auto complete results!

Re: Autocomplete Styling Puzzle

I got round to installing model_auto_completer again today. A 'check_permissions' before filter and the 'protect_from_forgery' were both breaking the ajax request (I didn't find a solution for the protect_from_forgery other than ignoring it for the controller auto_complete action).

However, once I was seeing results returned in the view, it appeared as though the auto completer was simply returning all the results in the collection (current_user.friends) rather than just the ones that matched the :name attribute. If I typed 'bob' I would get 'bob smith' plus everyone else in the collection. I'm leaving it for now as a collection select will work fine to begin with. I may come back to it though as I have an itch to fix it.

Re: Autocomplete Styling Puzzle

smile That itch is actually bugging me too now. Hope you get around to scratching it soon. I am guessing it must just be a little bit of logic in the query.  smile anyway, hope I helped. Thanks for yours!

Re: Autocomplete Styling Puzzle

I have the connect and it brought fine the first time. Had no troubles. Im completely 'doh!' about CSS so I havent got an estimate how to go about styling it like the way i referred.