rails autocomplete tags separated by commas using regex

前端 未结 2 890
礼貌的吻别
礼貌的吻别 2021-02-04 17:48

I am using the old auto_complete plugin in conjunction with the acts as taggable on gem in an attempt to basically replicate the tagging behavior of Stack Overflow itself! I am

2条回答
  •  悲&欢浪女
    2021-02-04 18:02

    I know this is old, but to recreate this behavior I used rails3-jquery-autocomplete with acts-as-taggable-on. They work very nicely and easily together.

    // Model
    class Foo < ActiveRecord::Base
      acts_as_taggable_on :tags
    end
    
    // Controller
    class FoosController < ApplicationController
      autocomplete :tag, :name, :class_name => 'ActsAsTaggableOn::Tag'
      ...
    end
    
    // Routes
    resources :foos do
      collection do
        get :autocomplete_tag_name
      end
    end
    
    //View
    <% form_for :foo do |form| %>
      <%= form.label :tag_list, "Tags" %>
      <%= form.autocomplete_field :tag_list, autocomplete_tag_name_foos_path, :"data-delimiter" => ', ' %>
    <% end %>
    

    Hope that helps someone.

提交回复
热议问题