0

I am using Rails acts_as_taggable_on plugin with Jquery TokenInput but when a tag is entered and space bar pressed (changed delimiter to spaces) the token cloud is not created. Also, my Json output file looks a bit strange, it's not outputting the correct number ID.

JSON Output

{"id":"Funny","name":"Funny"},{"id":"Basketball","name":"Basketball"}

Users Controller

 def tags 
  @tags = ActsAsTaggableOn::Tag.where("tags.name LIKE ?", "%#{params[:q]}%") 
  respond_to do |format|
    format.json { render :json => @tags.collect{|t| {:id => t.name, :name => t.name }}}
  end
end

User Model

class User < ActiveRecord::Base
   attr_accessible :name, :tag_list
   acts_as_taggable_on :tags
end

Javascript File

$(function() {
  $("#user_tags").tokenInput("/users/tags.json", {
    prePopulate:       $("#user_tags").data("pre"),
    preventDuplicates: true,
    noResultsText:     "No results, needs to be created.",
    animateDropdown:   false
  });
});

View

<h2>Enter new user:</h2>

<%= form_for @user do |f| %>

Name: <%= f.text_field :name %><br />
Tags: <%= f.text_field :tag_list,  :id => "user_tags",
                 "data-pre" => @user.tags.map(&:attributes).to_json %>


<%= f.submit %><br />
<% end %>
wolfbagel
  • 319
  • 3
  • 12

1 Answers1

0

try just doing

format.json { render :json => @tags}

also you don't see to change the delimiter to space..

Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244