Merbと違って、Railsには標準的なユーザ認証機構が用意されていないので、
昔から様々な認証用プラグインが乱立していました。
login_generator,
acts_as_authenticated,
restful_authentication,
restful_openid_authentication and so on...

今回は、@a_matsudaさんや
@lchinさんの勧めもあり、
比較的新しいClearanceという認証プラグインを試してみる事にしました。

インストール方法

config/environment.rbに

ruby>>
config.gem "thoughtbot-clearance",
:lib => 'clearance',
:source => 'http://gems.github.com',
:version => '>= 0.5.3'
<<--

config/environments/test.rbに

ruby>>
config.gem 'thoughtbot-shoulda',
:lib => 'shoulda',
:source => "http://gems.github.com",
:version => '>= 2.10.0'
config.gem 'thoughtbot-factory_girl',
:lib => 'factory_girl',
:source => "http://gems.github.com",
:version => '>= 1.2.0'
<<--

と記述し、

pre>>
% sudo rake gems:install
% sudo rake gems:install RAILS_ENV=test
<<--

あとは、

pre>>
% ./script/generate clearance
<<--

これでモデル、コントローラ、View、migrationファイルの作成が行われ、
マイグレーションの実行まで完了します。

続いて、config/environments/*.rb に、HOST="hostname"のようにホスト名を設定します。test, developmentでは"localhost"、
productionでは実際に使われるホスト名を指定すれば良いようです。
さらに、config/environment.rbの中で、

ruby>>
DO_NOT_REPLY = 'do_not_reply@s21g.com'
<<--

のように、アクティベーションメールの送信もとメールアドレスを設定します。

最後に、config/routes.rbの中で、何でも良いのでrootのNamedRouteを定義します。

ruby>>
map.root :controller => 'top'
<<--

以上で完了です。

追記

現時点でのバージョン(thoughtbot-clearance (0.5.3),
thoughtbot-factory_girl (1.2.0),
thoughtbot-shoulda (2.10.1))では、
clearanceに含まれているshoulda_macrosを手動でtest
ディレクトリの下にコピーする必要があるようです。

See Also

posted by genki genki on Mon 16 Mar 2009 at 16:13 with 0 comments
Contents rssrss
光ファイバーを二次元振動させて走査するAR用ディスプレイ
因果の取り違え
Swift2's defer for CoffeeScript
mongodb-3.0からcreateIndexのdropDupsが無くなったらしい
mongodb-3.0以降のWiredTigerの設定を動的に変更する方法
一般楕円の高速生成アルゴリズムへの道標
farro mantecatoのレシピ
Droonga関連の記事のまとめ
RuntimeErrorの特定のメッセージに限定してrescueする方法
jQueryでscriptタグを実行せずにappendする
Tags
coffeescriptdefergroongajsmemonodenodejs
Comments rssrss
https://overwatch2base.com/ https://overwatch2base.com/: Hello, i think that i saw you visited my site so i... 05/09 02:48
https://www.ehgdetailing.com.au/ https://www.ehgdetailing.com.au/: What's up Dear, are you actually visiting this web... 05/09 02:13
https://hockeycamp.co.kr/bbs/board.php?bo_table=free&wr_id=766425 https://hockeycamp.co.kr/bbs/board.php?bo_table=free&wr_id=766425: Kaizenaire.comis youг Singapore guide tо curated p... 05/09 00:22
https://stemacumen.net/blog/index.php?entryid=108295 https://stemacumen.net/blog/index.php?entryid=108295: Oⲣen the mοst effective οf Singapore's shopping at... 05/08 22:32
https://www.forwardcounselnil.com/discover-the-hottest-singapore-advertisings-and-offers-on-kaizenaire-com-5/ https://www.forwardcounselnil.com/discover-the-hottest-singapore-advertisings-and-offers-on-kaizenaire-com-5/: Kaizenaire.сom is yⲟur entrance to Singapore'ѕ lea... 05/08 19:54
http://arbims.arcosnetwork.org/op.setlang.php?lang=en_GB&referer=https%3A%2F%2Fwww.privikaarchitects.com%2F2026%2F04%2F21%2Fplinko-online-casino-game-review%2F http://arbims.arcosnetwork.org/op.setlang.php?lang=en_GB&referer=https%3A%2F%2Fwww.privikaarchitects.com%2F2026%2F04%2F21%2Fplinko-online-casino-game-review%2F: What's up i am kavin, its my first time to comment... 05/08 18:48
https://hoidotquyvietnam.com/question/discover-credit-card-promotions-and-deals-in-singapore-on-kaizenaire-com-66/ https://hoidotquyvietnam.com/question/discover-credit-card-promotions-and-deals-in-singapore-on-kaizenaire-com-66/: Kaizenaire.com succeeds аs Singapore's leading col... 05/08 16:38
https://Animegamerspot.com/ https://Animegamerspot.com/: Hey I know this is off topic but I was wondering i... 05/08 14:06