Skip to content
Tag? Tree? Tags like Tree
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
generators/acts_as_tagtree
lib
tasks
test
.autotest
MIT-LICENSE
README
Rakefile
init.rb

README

ActsAsTagtree
=============

== Installation

  $ ruby script/plugin install git://github.com/wosmvp/acts_as_tagtree.git

== Usage

=== Prepare database

  Generate and apply the migration:

  $ ruby script/generate acts_as_tagtree
  $ rake db:migrate

=== Basic tagging
------------------------------

  class Topic < ActiveRecord::Base
    acts_as_tagtree
  end

  t = Topic.find(:first)
  t.tag_list # []
  t.tag_list = "linux>vim>plugin;ruby>rails"
  t.save
  t.tag_list # ['linux>vim>plugin','ruby>rails']

------------------------------

  t.tag_list = "linux>vim>plugin;ruby>rails"
  t.tag_list = "Linux>emacs>plugin"
  ## Tag $id     $name    $fullname         $parent_id
         1       linux    linux               NULL
         2       vim      linux>vim           1
         3       plugin   linux>vim>plugin    2
         4       ruby     ruby                NULL
         5       rails    ruby>rails          4
         6       emacs    linux>emacs         1
         7       plugin   linux>emacs>plugin  6

------------------------------

=== Advance tagging

 Related Topic ( modle.find_related )
   # Find Related Topic: limit 10,offest 5,order by 'updated_at',DESC
   t.find_related(:num => [5,10],:key => 'updated_at',:reverse => true)

 All Topic     ( tag.all_*** )
   Topic.create(:title => 'vim', :tag_list => 'linux')
   Topic.create(:title => 'emacs',:tag_list => 'linux')
 
   Tag.find_by_fullname('linux').all_topics => [Topic(:vim),Topic(:emacs)]

=== Helper

  module ApplicationHelper
    include TagsHelper
  end
  # View Usage
  <%= taglist %>
  <%= tagslink(topic.tag_list) %>

=== Caching

  class CacheTopicTagList < ActiveRecord::Migration
    def self.up
      add_column :topics, :cached_tag_list, :string
    end
  end

==

Copyright (c) 2008 <Zhang Jinzhu>, released under the MIT license
Something went wrong with that request. Please try again.