Ruby on rails 让Rails3jQuery自动完成显示带有特定标记的文章实例数?
我有一个具有多对多关联的Post和Tag模型:Ruby on rails 让Rails3jQuery自动完成显示带有特定标记的文章实例数?,ruby-on-rails,Ruby On Rails,我有一个具有多对多关联的Post和Tag模型: class Post < ActiveRecord::Base attr_accessible :title, :content has_many :taggings, :dependent => :destroy has_many :tags, :through => :taggings end class Tag < ActiveRecord::Base has_many :taggings, :de
class Post < ActiveRecord::Base
attr_accessible :title, :content
has_many :taggings, :dependent => :destroy
has_many :tags, :through => :taggings
end
class Tag < ActiveRecord::Base
has_many :taggings, :dependent => :destroy
has_many :posts, :through => :taggings
has_many :subscriptions
has_many :subscribed_users, :source => :user, :through => :subscriptions
end
class Tagging < ActiveRecord::Base
belongs_to :post
belongs_to :tag
end
\u form.html.erb:
resources :posts do
get :autocomplete_tag_name, :on => :collection
end
<div class="field">
<%= f.label :tag_names %><br />
<%= f.autocomplete_field :tag_names, autocomplete_tag_name_posts_path, :"data-delimiter" => ' ' %>
</div>
(很像StackOverflow)
如果您有任何见解或示例代码,我将不胜感激
---------------------
| dr |
---------------------
|drinks (23) |
|drugs (4) |
| |
---------------------