Ruby-on-Rails

Implementing Tagging Support

In this third part to a four-part article series on implementing tagging support for an ecommerce website using Ruby-on-Rails, you'll learn how to set up the application so users can assign tags to items. This article is excerpted from chapter seven of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Next, we need to change the view. As we explained earlier, the view should have an autocompletion field where George can enter the tags. This functionality could easily be implemented with Ajax, but instead, we’ll do it the old-school way with plain JavaScript—just to save some resources and a couple of Ajax calls to the server.

The tags will be stored in a JavaScript variable and passed to theAutocompleter.Localhelper provided byscript.aculo.us.

Notice that we specify the tag separator to be a comma with thetokensparameter. This is an array and can contain more than one separator. For example, it could also contain the new-line character\n. Also notice that the tags will be shown in thetags_update div.