Ruby on Rails プラグイン まとめ wiki
http://w.atwiki.jp/maimuzo/
Ruby on Rails プラグイン まとめ wiki
ja
2012-05-30T07:48:11+09:00
1338331691
-
静的コンテンツ及びログ(Statistics and Logs)
https://w.atwiki.jp/maimuzo/pages/64.html
script/plugin install git://github.com/mbleigh/twitter-auth.git
2012-05-30T07:48:11+09:00
1338331691
-
コメント/acts_as_commentableプラグイン
https://w.atwiki.jp/maimuzo/pages/63.html
-good morning - k 2011-08-29 14:04:14
2011-08-29T14:04:13+09:00
1314594253
-
Rails用エンジン(Rails Engines)
https://w.atwiki.jp/maimuzo/pages/62.html
日本語
2010-06-29T15:22:31+09:00
1277792551
-
メニュー2
https://w.atwiki.jp/maimuzo/pages/3.html
いづれも実際に自分で買ったもので、オススメなものです。
Ruby on Railsを覚えるならコレです。
#amazon(4798013951,center,text,image)
----
慣れないとちょっと難しいRailsの運用まで書かれているのはコレです。
#amazon(4797335750,center,text,image)
----
Rubyの文法や突っ込んだ仕組みが知りたければコレです。
#amazon(4274066428,center,text,image)
#javascript(){{
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
var pageTracker = _gat._getTracker("UA-1165680-2");
pageTracker._initData();
pageTracker._trackPageview();
}}
#javascript(){{
<!-- nakanohito -->
<script LANGUAGE="Javascript">
<!--
var refer = document.referrer;
document.write("<a href='http://nakanohito.jp/'>");
document.write("<img src='http://nakanohito.jp/an/?u=170528&h=737479&w=128&guid=ON&t=&version=js&refer="+escape(parent.document.referrer)+"&url="+escape(parent.document.URL)+"' border='0' width='128' height='128' />");
document.write("</a>");
//-->
</script>
<noscript>
<img src="http://nakanohito.jp/an/?u=170528&h=737479&w=128&guid=ON&t=" width="128" height="128" alt="" border="0" />
</noscript>
<!-- nakanohito end -->
<script type="text/javascript" charset="utf-8" src="http://parts.logoole.yahoo.co.jp/parts/script/h1p3nt24fhcdlo95gfwj9axxswk8eiow"></script><div class="yahoo-tracks-widget"></div>
}}
2009-01-08T14:21:09+09:00
1231392069
-
SafeERBプラグイン
https://w.atwiki.jp/maimuzo/pages/52.html
**プラグイン名
SafeERBプラグイン
**このプラグインができること
+ERBテンプレートで、<%= ar.hoge %>など、DBや入力パラメータ由来の文字に対して、サニタイズを忘れていたときに例外を出してくれる
**ちょー簡単な使い方
>./script/plugin install http://safe-erb.rubyforge.org/svn/plugins/safe_erb
これだけ。簡単。
**公式ページ
-[[Safe ERB in Ruby on Rails>>http://wiki.rubyonrails.com/rails/pages/Safe+ERB]]
**日本語解説ページ
-ないねぇ。を、[[Ruby札幌の資料>>http://ruby-sapporo.org/events/rsn/6/]]があったか。
**外国語解説ページ
-[[SafeErb for Rails 2>>http://www.rorsecurity.info/2008/01/06/safeerb-for-rails-2/]]
**のうはう
-例外を出すかどうかはtaintという機能(? フラグ?)を使っている
-DBや入力パラメータ由来の文字はtaint状態になっていて、手動でコレを解除するにはstring.untaintとすればよい
-SafeERBプラグインではERB::Util#h(<%=h ar.hoge %>みたいなやつ)とActionView::Helpers::TextHelper#strip_tags(<%= ar.hoge.strip_tags %>みたいなやつ)を拡張しているので、これを使ったときには自動的にuntaintが呼ばれるので例外が発生しない
**コメント
#pcomment(reply)
2008-10-09T09:12:53+09:00
1223511173
-
acts_as_commentableプラグイン
https://w.atwiki.jp/maimuzo/pages/46.html
**プラグイン名
acts_as_commentableプラグイン
**このプラグインができること
+いろんなモデルにコメント(デフォルトだとタイトルと本文)を付けれる
+ユーザモデルと連動して、
-特定ユーザがコメントしたコメント一覧
-特定ユーザがコメントした対象モデル一覧
-対象モデルへのコメント一覧
を取得可能
**対象バージョン
1.2系 2.0系 2.1系
**ちょー簡単な使い方
>script/plugin install http://juixe.com/svn/acts_as_commentable
でインストールして、マイグレーションしてから
>class Post < ActiveRecord::Base
> acts_as_commentable
>end
ARにacts_as_commentable入れて
> post.comments << Comment.new(:title => titleStr, :comment => commentStr) #コメント追加
> post.comments #全コメント
> comments = Comment.find_comments_by_user(userInstance) #特定ユーザのコメント一覧
> postComments = Post.find_comments_by_user(userInstance) #特定ユーザがコメントしたモデル一覧
で幸せに。
**公式ページ
[[Juixe TechKnow » Acts As Commentable Plugin>>http://www.juixe.com/techknow/index.php/2006/06/18/acts-as-commentable-plugin/]]
※いや、公式かどうかはわからない
**日本語解説ページ
-見つからない
**外国語解説ページ
-良いところがない
**のうはう
-Commentモデルは、このプラグインに付いてくるので、作らなくて良い
-このデフォルトのCommentモデルには、Userモデルへの関連が付いているので、ユーザ情報管理モデルはUserが好ましい。
-プラグインの中のモジュールを読めば解るが、commentsテーブルにはuser_idカラムがあるものの、Userモデルからhas_manyで関連づけする必要はない。特定ユーザが書いたコメントだけ取得したければ、Comment.find_comments_by_user()で絞り込むので、Userモデル側にhas_manyなくても問題無い(User#commentsとかしない)ということ。
-マイグレーションファイルの構造を載せておく
> class AddRatingTables < ActiveRecord::Migration
> def self.up
> create_table :comments, :force => true do |t|
> t.column :title, :string, :limit => 50, :default => ""
> t.column :comment, :string, :default => ""
> t.column :created_at, :datetime, :null => false
> t.column :commentable_id, :integer, :default => 0, :null => false
> t.column :commentable_type, :string, :limit => 15,
> :default => "", :null => false
> t.column :user_id, :integer, :default => 0, :null => false
> end
> add_index :comments, ["user_id"], :name => "fk_comments_user"
> end
> def self.down
> drop_table :comments
> end
> end
#image(http://farm4.static.flickr.com/3137/2780685717_42b51ba69a.jpg)
[[WWW SQL Designerファイル>http://www13.atwiki.jp/maimuzo?cmd=upload&act=open&pageid=46&file=acts_as_commentable.xml]]
**コメント
#pcomment(reply)
2008-10-08T16:54:50+09:00
1223452490
-
トップページ
https://w.atwiki.jp/maimuzo/pages/1.html
*Ruby on Rails プラグイン まとめ wiki
today &counter(today) / yesterday &counter(yesterday) / total &counter()
このウィキの最終更新日時は&last_modified()です
**はじめに
-現在フリーでお仕事募集中です。連絡を取りたい方は&link_mail(maimuzo@gmail.com,subject=from_wiki){こちら}までどうぞ。
-このwikiは内容が不足しています。左メニューの更新履歴を追うか、情報元またはその他まとめサイトも見ると幸せになれるかもしれません。
-更新ペースは私の学習ペースです。
**wiki内検索
#search3(title=全文検索,submit=検索する,size=10,ignore=own,or)
※プラグイン一覧を調べたいときは「プラグイン」で検索すると幸せになれるかもしれません。
#tagsearch2(title=タグ検索,submit=検索する,size=10,show_tag_and_page,or)
※プラグイン一覧を調べたいときには「plugin」で検索すると幸せになれるかもしれません。
#include(RubyOnRailsプラグインのカテゴリー)
**その他雑多
-[[maimuzoが個人的にオススメするプラグイン]]
-[[maimuzo的ベストプラクティス]]
-[[その他Ruby系]]
-[[その他Rails系]]
-[[逆引きプラグイン]]
-[[まとめサイト]]
-[[自作Gem]]
-[[WANTED]] (情報お持ちの方教えてください)
**このwikiについて
-このwikiは、Ruby on Rails(以後ROR)のプラグインの種類・用途・完成度などについて、個人のアレコレを元にまとめているものです。
-内容についてはなんら保証ありませんし、このwikiを信じて転んでも責任は被りません。
-プログイン側のバージョンアップなどによって、以前に正解だった内容が、間違いになっている可能性もあります。(Railsの場合多いです)
-最終更新時間を元に自己判断してください。
-既に見つけることが出来るものはそのリンクを、見つけることが出来ないものは試してみるか翻訳したものをまとめる方針です。
**おやくそく・許可など
-メニューに類するページ以外は誰でも書き込み可ですが、公益に反すると管理人が判断した場合は、該当部分を削除しちゃうかもしれません。
-非ログインユーザは編集時にIPを保存します。ただし、当面の間は管理人だけ見ることが出来るようにします。
-悪意のある書き込みと判断した場合にはIPを曝すかもしれません。
-このサイトのコンテンツは、[[Agile Web Development>>http://agilewebdevelopment.com]]からの翻訳コンテンツを含みます。Agile Web Developmentの管理者であるBenjamin Curtisさんから翻訳許可を得ています。
-翻訳コンテンツについても、事実の有無、翻訳の精度、その他一切保証しません。ヘタレな翻訳は突っ込みお願いします。
**特設ページ
Gem関係の情報集約サイトであるgemspec.infoのための特設ページです
-[[GemSpec.info]]
**最近の更新内容
#recent(30)
**[[wikiの使い方]]へ
2008-10-07T15:36:10+09:00
1223361370
-
open_id_authenticationプラグイン
https://w.atwiki.jp/maimuzo/pages/61.html
**プラグイン名
open_id_authenticationプラグイン
*setup
**何が出来るか
-OpenIDを使ってユーザ登録やログインする処理を作る
-OpenID Providerからの追加属性(メアドとか性別とか)取得サポート(SREG)
-OpenID Providerをホワイトリスト/ブリックリストで制限する
-OpenID URLからOpenID ProviderのURL(Endpoint URL)を調査して、上記ホワイト/ブラックリストに追加するための[[スクリプト>>http://www13.atwiki.jp/maimuzo?cmd=upload&act=open&pageid=61&file=endpoint.rb]]も用意(Maimuzoが適当に作った物)
-open_id_authenticationプラグインは、部品を提供しているに過ぎなく、ジェネレータなどは付いてこないので、基本的に処理は自分で作る必要がある
**方針
-結局、どんな機能が必要で、認証できた/出来なかったときどうしたいかは、アプリ毎に違うので定型化しない方がよい
-でも、フルスクラッチで作ると辛い
-open_id_authenticationを部品として使い、細かいところは自分で作る
-ジェネレータで作るより、コピペでがりがりやる。(ジェネレータ無いし)
-open_id_authenticationプラグイン自体にも手を入れる(そのままだとエラーの振り分けさえ出来ないので)
-下記コードをそのまま動かすには、[[改造版>>http://www13.atwiki.jp/maimuzo?cmd=upload&act=open&pageid=61&file=open_id_authentication.rb]]が必要。これをvender/plugins/open_id_authentication/libに上書きして使う
**標準作業
# sudo gem install ruby-openid
# script/plugin install open_id_authentication
# rake open_id_authentication:db:create
# rake db:migrate
**お好みで
***他の認証系プラグインを使わないならUserモデルを自作する必要がある
# script/generate model User nickname:string email:string claimed_url:string fullname:string birth_date:string gender:integer postcode:string country:string language:string timezone:string
***以下のホワイト/ブラックリスト形式でOpenIDプロバイダに制限を加えるなら、そのリストを作る
# script/generate model TrastedOpenidProvider endpoint_url:string
**ログインしないと見れないページがあるならapp/controllers/application.rbに追加する
class ApplicationController < ActionController::Base
# 未ログイン状態でログインが必要なページに入ろうとすると、元のページに戻される
# ログイン専用ページがない場合など
def block_until_authorized
unless login?
flash[:notice] = "Please log in"
redirect_to(request.referer)
end
end
# ログインが必要なページならば認証ページをはさみ、認証したらそのページに誘導する
# ログイン専用ページがある場合など
# 一部
# http://japan.internet.com/column/developer/20080627/26.html
# を参考に書き換え必要
def go_through_authorized
unless login?
flash[:notice] = "Please log in"
# save the URL the user requested so we can hop back to it
# after login
session[:jumpto] = request.parameters
redirect_to("/login")
end
end
end
**add to app/helper/application_helper.rb
module ApplicationHelper
def login?
session[:user_id]
end
def logined_user
User.find(session[:user_id])
end
end
**ログインが必要なページを指定する
class SomeController < ApplicationController
before_filter :block_until_authorized,
:only => [ :new , :edit, :create, :update, :destroy]
end
**セッションコントローラーの作成
***generate controller
# script/generate controller sessions
***set route to config/routes.rb(RESTful風味)
map.open_id_complete 'session', :controller => "sessions", :action => "create", :requirements => { :method => :get }
map.resource :session
map.login '/login', :controller => 'sessions', :action => 'new'
map.logout '/logout', :controller => 'sessions', :action => 'destroy'
***paste this controller
class SessionsController < ApplicationController
# TODO:change default page
@@default_page = "/"
# require property from a OpenID provider
# [:(User model property) => "(OpenID provider property in sreg)"]
@@required = {
:nickname => "nickname",
:email => "email"
}
# optional property from a OpenID provider (sreg)
# [:(User model property) => "(OpenID provider property in sreg)"]
@@optional = {
:fullname => "fullname",
:birth_day => "dob",
:gender => "gender",
:postcode => "postcode",
:country => "country",
:language => "language",
:timezone => "timezone"
}
# TODO:if your app has an especialy login page, you can use this index action
# GET /sessions/new
def new
#redirect_to :controller => "TODO::your_logined_user_controller" if login?
redirect_to default_page
end
# POST /sessions
def create
if using_open_id?
open_id_authentication
else
flash[:error] = "You must provide an OpenID URL"
redirect_to tyied_page
end
end
# DELETE /sessions
# GET /logout
def destroy
session[:user_id] = nil
redirect_to default_page
end
protected
def open_id_authentication
# request options
# :whitelist and :blacklist require ActiveRecord class
# need to modify oepn_id_authentication.rb
options = {
:required => @@required.values.map {|str| str.to_sym},
:optional => @@optional.values.map {|str| str.to_sym},
:whitelist => TrastedOpenidProvider,
:target_column => "endpoint_url"
}
authenticate_with_open_id(params[:openid_url], options) do |status, identity_url, registration|
case status.result
when :found_in_whitelist_or_blacklist
failed_login "Sorry, the OpenID server is blocked by the white list"
when :double_auth
failed_login "Error, detect a double autentication"
when :missing
failed_login "Sorry, the OpenID server couldn't be found"
when :canceled
failed_login "OpenID verification was canceled"
when :failed
failed_login "Sorry, the OpenID verification failed"
when :successful
if @current_user = User.find_by_claimed_url(identity_url)
successful_login
else
@current_user = User.new
assign_registration_attributes!(registration)
@current_user.claimed_url = identity_url
@current_user.nickname = identity_url.delete("http://")[0..8] if @current_user.nickname.blank?
if @current_user.save
successful_login
else
failed_login "Your OpenID profile registration failed: " +
@current_user.errors.full_messages.to_sentence
end
end
end
end
end
def successful_login
session[:user_id] = @current_user.id
#jumpto = session[:jumpto] || default_page
#session[:jumpto] = nil
#redirect_to(jumpto)
redirect_to(root_url)
end
def failed_login(message)
flash[:error] = message
redirect_to default_page
end
# if you don't use map.resource in config/routes.rb, you need to use root_url method:
# def root_url
# # TODO:check with config/routes.rb
# open_id_complete
# end
def default_page
@@default_page
end
def tyied_page
request.referer
end
# registration is a hash containing the valid sreg keys given above
# use this to map them to fields of your user model
def assign_registration_attributes!(registration)
model_to_registration_mapping.each do |model_attribute, registration_attribute|
unless registration[registration_attribute].blank?
@current_user.send("#{model_attribute}=", registration[registration_attribute])
end
end
end
# TODO:change this hash like your user model.
def model_to_registration_mapping
@@required.merge(@@optional)
end
end
**必要ならapp/views/sessions/new.html.erbを作る
<% if flash[:error] -%>
<%= flash[:error] %>
<% end -%>
<% form_tag(session_url) do |f| -%>
<label for="openid_url" >
OpenId URL:
</label>
<%= text_field_tag :openid_url -%>
<%= submit_tag "Login" -%>
<% end -%>
**公式ページ
[[GitHubのページ>>http://github.com/rails/open_id_authentication/tree/master]]
※いや、公式かどうかはわからない
**日本語解説ページ
-[[OpenID系の比較>>http://www13.atwiki.jp/maimuzo/pages/43.html]]
**外国語解説ページ
-良いところがない
**のうはう
-マイグレーションファイルの構造を載せておく
> class AddOpenIdAuthenticationTables < ActiveRecord::Migration
> def self.up
> create_table :open_id_authentication_associations, :force => true do |t|
> t.integer :issued, :lifetime
> t.string :handle, :assoc_type
> t.binary :server_url, :secret
> end
> create_table :open_id_authentication_nonces, :force => true do |t|
> t.integer :timestamp, :null => false
> t.string :server_url, :null => true
> t.string :salt, :null => false
> end
> end
> def self.down
> drop_table :open_id_authentication_associations
> drop_table :open_id_authentication_nonces
> end
> end
#image(http://farm4.static.flickr.com/3285/2861268523_0ae9c2d71b_o.jpg)
[[WWW SQL Designerファイル>http://www13.atwiki.jp/maimuzo?cmd=upload&act=open&pageid=61&file=open_id_authentication.xmll]]
**コメント
#pcomment(reply)
2008-10-07T15:35:23+09:00
1223361323
-
セキュリティ(Security)
https://w.atwiki.jp/maimuzo/pages/13.html
-[[Acts as Authenticatedプラグイン]]
-[[SafeERBプラグイン]]
-[[open_id_authenticationプラグイン]]
2008-10-07T15:19:53+09:00
1223360393
-
逆引きプラグイン
https://w.atwiki.jp/maimuzo/pages/43.html
使い分けや逆引き風にまとめたものです。
カテゴリ目次
#contents()
**黙って最初から導入
よく実テーブル上のカラム名や形や長さを忘れてしまうので、[[paginating_findプラグイン]]を使ってmodelにスキーマをメモしています。
Gemだけど、[[Capistrano]]を使ってデプロイ出来るのと出来ないのでは、開発効率が大きく違います。
Rails1.x系でのPagenateは、機能としては便利なのですがデータの持ち方に癖があるので、あまりそれを応用したプラグインが無かったりします。またRails2.x系だと、そんなこともあってPagenate自体がなくなりました(Rails標準ではなくプラグインを使うことが前提となった)。そんな時に使うのが[[paginating_findプラグイン]]で、これだと標準のfindメソッドを拡張してくれます。
**ログイン処理
***Rails 1.x系
[[Acts as Authenticatedプラグイン]]が標準か?
***Rails 2.x系
これが一番ってのは無いみたい。OpenIDを絡めて比較してみると・・・
|機能|Restful Authentication|open_id_authentication|openid_fu_generator|restful_open_id_authentication_redux|
|ユーザ登録|○|×|○|○|
|ログイン(認証)|○(パスワード)|○(OpenID)|○(パスワード/OpenID)|○(パスワード/OpenID)|
|セッション管理|○|×|○|○|
|アクセス制御|△|×|○|○|
|ログアウト|○|×|○|○|
|アカウント管理|×|×|○|○|
|形態|plugin|plugin|gem|plugin|
|OpenIDの対応バージョン|×|2.0|2.0|?(1.0かも)|
|備考|OpenID使わない場合デファクトスタンダードらしい|シンプルにOpenIDの認証機能だけ提供。普通はRestful Authenticationと組み合わせるらしい|パスワード+OpenIDなら一番しっかりしてる感じがする。細かいところでredux(→)よりよさげなところが見える|Restful Authenticationとopen_id_authenticationが最初から組み合わさっている感じなんだろうか。Rails2.1でも動く|
まーでも、実際に使ってみた訳じゃなくて、ソース追った程度だからね。はまりポイントがあるのかもしれないし。
全部ruby-openidってgemを使ってるのかな(未確認)
→色々はまったので追記
****まずruby-openid
このgemかなり良くできていて、他のプラグインなどはほとんどruby-openidに依存しているんだけど、ruby-openidだけを使って認証システムを作るにはOpenIDに対して精通してないと無理っぽい。各クラスやメソッドの意味とか流れを把握してないと、これだけで組むのは辛いって事。
****次openid_fu_generator
見た目は一番リッチな機能を提供してくれそうなんだけど、バージョン0.0.1からあがってないし、使ってみたらsessionsコントローラのbeginアクションの一番最初の分岐で止まる。ソースを追ったけど、下手に機械的なコードを隠蔽しているせいで、流れを追うのが難しい。結局原因解明できなかったのであきらめ。ちなみにrails2.1.1+ruby-openid2.1.2+openid_fu_generator0.0.1で試してました。
****次open_id_authentication
シンプルにruby-openidのラッパーとして動くみたいだけど、他のプラグインと違うのは、migrationファイルやライブラリは提供するものの、ジェネレータなどは付属してないため、UserコントローラやSessionコントローラを自作する必要があるって事。まぁ、単体で使うことは想定してないんだろうな。
見ておくべきは[[OpenIDとRails:Authentication 2.0>>http://japan.internet.com/column/developer/20080627/26.html]](すばらしすぎ)と、open_id_authenticationのREADMEにサンプルソースがついてるので、それを交互に見ながら何やってるかを追えば、結構簡単に認証処理も作れるっぽい。SREG(Simple Registration Extension for OpenID)の対応もサクッとできそう。ホワイトリスト的に受付可能なOpenID Providerを絞るのも、[[第5回 Railsで作るOpenID対応アプリケーション実践(後編)(3)>>http://gihyo.jp/dev/feature/01/openid/0005?page=3]]の流れでサクッとはじけれそう。(あとはJavaScriptのライブラリとして、受付可能なOpenID Providerをリスト表示してくれるものがあればいいんだけど…)
****参考
-[[Railsで作るOpenID対応アプリケーション実践(前編)>>http://gihyo.jp/dev/feature/01/openid/0004]]
-[[restful_open_id_authentication_redux - Hello, world! - s21g>>http://blog.s21g.com/articles/278]]
-[[Plugins - Open Id Authentication - Agile Web Development>>http://agilewebdevelopment.com/plugins/openidauthentication]]
****データベース構造
#image(http://farm4.static.flickr.com/3128/2861255363_2720fb4450_o.jpg)
#image(http://farm4.static.flickr.com/3285/2861268523_0ae9c2d71b_o.jpg)
#image(http://farm4.static.flickr.com/3143/2861289573_991ef06a4f_o.jpg)
#image(http://farm4.static.flickr.com/3224/2862108466_60deac2bd6_o.jpg)
**ファイルアップロード処理
[[Attachment_fuプラグイン]]が使えるなら使った方が楽かもね。
**レーティング系
acts_as_ratableプラグインが良さそう→否
rails 2.1系でacts_as_rateableが[[エラーを出している>http://agilewebdevelopment.com/plugins/acts_as_rateable]]みたい。あまりスケールしないとも書いてあるなぁ。
となったら、acts_as_ratedがいいのかもしれない。
**タギング系
acts_as_taggable_on_steroidsとacts_as_taggable_reduxが良さそう
使い分けは
-自分で作った何かにタグを付けるならsteroids
-他人が作った何かにタグを付けるならredux
みたい
-[[acts_as_taggable_on_steroidsとacts_as_taggable_reduxの(用途)比較CommentsAdd Star>>http://d.hatena.ne.jp/yotena/20071220/1198103145]]
***データベース構造
#image(http://farm4.static.flickr.com/3227/2861719571_8d709e1430_o.jpg)
2008-10-06T15:01:15+09:00
1223272875