acts_as_taggable_on_steroidsを試してみた。
いつものように
Rails Tagging in The Ruby Toolbox
で探してみるもリンク先が古く、ちょっと手間取った(最後に書く)。
インストール
$ ruby script/plugin install git://github.com/jviney/acts_as_taggable_on_steroids.git $ ruby script/generate acts_as_taggable_migration $ rake db:migrate
taggingsとtagsテーブルが作成される。
helper
module ApplicationHelper include TagsHelper end
model
acts_as_taggableを追加するだけ。
class Article < ActiveRecord::Base acts_as_taggable end
controller
tag_countsを使用してviewにインスタンス変数として渡すだけ。
def index @tags = Article.tag_counts @articles = Article.all end
view
tag_cloud / tag_listを使うだけ。
#index.html.erb <% tag_cloud @tags, %w(css1 css2 css3 css4) do |tag, css_class| %> <%= link_to(tag.name, { :action => :tag, :id => tag.name }, :class => css_class) %> <% end %> #new.html.erb / edit.html.erb <p> <%= f.label :tag_list, 'タグ' %><br /> <%= f.text_field :tag_list %> </p>
css
ここはviewと合わせてお好きに。
(↓はreadmeから)
.css1 { font-size: 1.0em; } .css2 { font-size: 1.2em; } .css3 { font-size: 1.4em; } .css4 { font-size: 1.6em; }
ruby-toolboxリンク先が古い?
http://github.com/mattetti/acts_as_taggable_on_steroids
になってて、このreadmeの通りにinstallしたものを使うと
エラーとなる。
正常に動作したのは上にも書いたようにこっち
http://github.com/jviney/acts_as_taggable_on_steroids
ruby script/plugin install http://svn.viney.net.nz/things/rails/plugins/acts_as_taggable_on_steroids
こんなエラー
RuntimeError: acts_as_taggable_on_steroids has been moved to github: http://github.com/jviney/acts_as_taggable_on_steroids
$ rake db:rollback $ ruby script/plugin remove acts_as_taggable_migration $ git clone -f $ git clear -f
gitいい!