Tag: tag it

acts_as_taggable_on标签已添加两次

我有一个RoR应用程序,允许用户标记其集合中的项目。 我使用tag-it.js Jquery插件并使用Ajax调用来添加和删除ItemsController中的标签。 我的问题是每个标记都添加了两次,这样当我执行@ item.tags.each时,所有标记都会显示两次。 上述ItemsController: def add_tag @collection = current_user.collections.find(params[:collection_id]) @item = @collection.items.find(params[:id]) @item.tag_list.add(params[:tag]) current_user.tag(@item, :with => @item.tag_list.to_s, :on => :tags) @item.save render nothing: true end def remove_tag @item = current_user.items.find_by_id(params[:id]) @item.tag_list.remove(params[:tag]) current_user.tag(@item, :with => @item.tag_list.to_s, :on => :tags) @item.save render nothing: true end 使用Tag-it.js处理AJAX标记的Javascript: $(‘#item_tags’).tagit({ onTagAdded: function(event, tag) { var add_url = $(‘#item_tags’).attr(“data-add-url”); […]