「acts_as_favoriteプラグイン」の編集履歴(バックアップ)一覧はこちら
追加された行は緑色になります。
削除された行は赤色になります。
**プラグイン名
acts_as_favoriteプラグイン
**このプラグインができること
+ユーザ毎にお気に入り(モデル内の特定レコード)を管理できる
+このユーザはBookモデルのid=1と4と23をお気に入りに登録してある、みたいな感じ
**ちょー簡単な使い方
>script/plugin install http://svn.webwideconsulting.com/plugins/acts_as_favorite/
でインストールして、RAILS_HOMEにて
>script/generate favorite_model Favorite
とすると、Favoriteモデルとマイグレーションファイルが生成されるので、
>rake db:migrate
して、ユーザモデルに(acts_as_authenticated系使ったらこんなシンプルじゃないけど)
>class User < ActiveRecord::Base
> acts_as_favorite_user
>end
を追加し、お気に入りに登録可能にしたいモデル全てに
>class Blog < ActiveRecord::Base
> acts_as_favorite
>end
としておくと、以下のようなメソッドが使えるようになる。
お気に入りに追加
> current_user.has_favorite(Blog.find(43))
お気に入りから削除
> current_user.has_no_favorite(Blog.find(43))
お気に入りへの追加状況確認(returns true/false):
> current_user.has_favorite?(Blog.find(99)) #=> true/false
> current_user.has_favorite_blogs? #=> true/false Blogモデルはこのユーザのお気に入りに登録されているか?
検索
>current_user.all_favorites (ユーザのお気に入りが全て返る。blogsや他のモデルも一緒くた)
>current_user.favorite_blogs (ユーザのお気に入りのうちBlogモデルに関する分だけ返る)
>Blog.find(43).favorite_users (このレコードをお気に入りに入れた全ユーザが返る)
**公式ページ
-どこなんだろうね?
**日本語解説ページ
-見つからない
**外国語解説ページ
-[[Plugins - Acts as Favorite - Agile Web Development>>http://agilewebdevelopment.com/plugins/acts_as_favorite]]
-[[spotstory » acts_as_favorite>>http://blog.spotstory.com/2006/12/26/acts_as_favorite/]]
※プラグインインストール時にサンプルが表示されるけど、それ見ても良い(英語)
**のうはう
-バグがあったようだけど、本家にマージされたみたい
-マイグレーション内容
>class CreateFavorites < ActiveRecord::Migration
> def self.up
> create_table :favorites, :force => true do |t|
> t.column :user_id, :integer
> t.column :favorable_type, :string, :limit => 30
> t.column :favorable_id, :integer
> t.column :created_at, :datetime
> t.column :updated_at, :datetime
> end
> end
> def self.down
> drop_table :favorites
> end
>end
#image(http://farm4.static.flickr.com/3017/2784562124_c9a0baa18e.jpg?v=0)
[[WWW SQL Designer>http://www13.atwiki.jp/maimuzo?cmd=upload&act=open&pageid=45&file=acts_as_rated.xml]]
**コメント
#pcomment(reply)
**プラグイン名
acts_as_favoriteプラグイン
**このプラグインができること
+ユーザ毎にお気に入り(モデル内の特定レコード)を管理できる
+このユーザはBookモデルのid=1と4と23をお気に入りに登録してある、みたいな感じ
**ちょー簡単な使い方
>script/plugin install http://svn.webwideconsulting.com/plugins/acts_as_favorite/
でインストールして、RAILS_HOMEにて
>script/generate favorite_model Favorite
とすると、Favoriteモデルとマイグレーションファイルが生成されるので、
>rake db:migrate
して、ユーザモデルに(acts_as_authenticated系使ったらこんなシンプルじゃないけど)
>class User < ActiveRecord::Base
> acts_as_favorite_user
>end
を追加し、お気に入りに登録可能にしたいモデル全てに
>class Blog < ActiveRecord::Base
> acts_as_favorite
>end
としておくと、以下のようなメソッドが使えるようになる。
お気に入りに追加
> current_user.has_favorite(Blog.find(43))
お気に入りから削除
> current_user.has_no_favorite(Blog.find(43))
お気に入りへの追加状況確認(returns true/false):
> current_user.has_favorite?(Blog.find(99)) #=> true/false
> current_user.has_favorite_blogs? #=> true/false Blogモデルはこのユーザのお気に入りに登録されているか?
検索
>current_user.all_favorites (ユーザのお気に入りが全て返る。blogsや他のモデルも一緒くた)
>current_user.favorite_blogs (ユーザのお気に入りのうちBlogモデルに関する分だけ返る)
>Blog.find(43).favorite_users (このレコードをお気に入りに入れた全ユーザが返る)
**公式ページ
-どこなんだろうね?
**日本語解説ページ
-見つからない
**外国語解説ページ
-[[Plugins - Acts as Favorite - Agile Web Development>>http://agilewebdevelopment.com/plugins/acts_as_favorite]]
-[[spotstory » acts_as_favorite>>http://blog.spotstory.com/2006/12/26/acts_as_favorite/]]
※プラグインインストール時にサンプルが表示されるけど、それ見ても良い(英語)
**のうはう
-バグがあったようだけど、本家にマージされたみたい
-マイグレーション内容
>class CreateFavorites < ActiveRecord::Migration
> def self.up
> create_table :favorites, :force => true do |t|
> t.column :user_id, :integer
> t.column :favorable_type, :string, :limit => 30
> t.column :favorable_id, :integer
> t.column :created_at, :datetime
> t.column :updated_at, :datetime
> end
> end
> def self.down
> drop_table :favorites
> end
>end
#image(http://farm4.static.flickr.com/3017/2784562124_c9a0baa18e.jpg?v=0)
[[WWW SQL Designer>http://www13.atwiki.jp/maimuzo?cmd=upload&act=open&pageid=54&file=acts_as_favorite.xml]]
**コメント
#pcomment(reply)