Skip to content

Instantly share code, notes, and snippets.

@rujmah
Created June 19, 2012 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rujmah/2955196 to your computer and use it in GitHub Desktop.
Save rujmah/2955196 to your computer and use it in GitHub Desktop.
Generating tags with js-TokenInput and Mongoid in Rails

See Ryan's RailsCast on js-TokenField http://railscasts.com/episodes/258-token-fields-revised

This is how to Mongoid-ize it

Note: make sure you specify '_id' instead of the default 'id'

item js.coffee

jQuery ->
  $('#gift_tag_tokens').tokenInput '/tags.json'
    propertyToSearch: 'title', theme: 'facebook', tokenValue: '_id'
    prePopulate: $('#gift_tag_tokens').data('load')

tags controller

     def index
       @tags = Tag.asc(:title)
       
       respond_to do |format|
         format.html
         format.json { render json: @tags.where({title: /#{params[:q]}/})  }
       end
     end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment