views:

610

answers:

2

I've just started new branch of my project, where I try to use jRails. As far everything works awesome, except the autocomplete (especially text_field_with_auto_complete). What would be the best solution to make autocomplete working again?

  1. implement whole autocomplete by myself (I don't really like this one)
  2. rewrite the old prototype helper in jquery and then hack it into jRails
  3. use some out of box jquery plugin
+1  A: 

I'd go with option 3, and It's what I currently use in many programs. There are some plugins that achieve the same goal. One of it is this but most of them will work fine.

Basically what you will need to do is create the plugin, set it to look at your text field and then set it to some route.

This is some code from some old project I got at hand:

        $("input#send_detail_product_id").autocomplete("products/auto_complete_for_send", {  
     formatItem:formatItem,
                callback:processProduct;

});

The plugin I used didn't accept callback functions, so I hacked it a little and work it out. I can send it a function to process after selecting a file.

On the Rails controller, you can specify some logic and return your search results either as JSON or through a View file for formatting issues. In my case, the latter allows me to change how the product name looks.

It's really quite easy to accomplish with the added bonus of dealing with unobtrusive code.

Yaraher
+1  A: 

A JRails auto complete plugin is available

http://github.com/evilmarty/jrails_auto_complete

Midday