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
http://series60.ru/go.php?url=https://www.518fans.com/ http://series60.ru/go.php?url=https://www.518fans.com/: Article writing is also a fun, if you be familiar ... 05/30 20:49
https://www.1337games.org/online-casinos/betaalmogelijkheden/ideal/ https://www.1337games.org/online-casinos/betaalmogelijkheden/ideal/: 优质xxx平台 提供高质量的成人娱乐内容。选择 有保障的平台 以获得安全且愉快的观看体验。 05/30 20:44
https://scapaflow.org https://scapaflow.org: Thank you for the good writeup. It in fact was a a... 05/30 19:28
https://selebostore.com/forums/users/raymonlavigne/edit/?updated=true/users/raymonlavigne/ https://selebostore.com/forums/users/raymonlavigne/edit/?updated=true/users/raymonlavigne/: Ꭺs Singapore’ѕ premier furniture store and compr... 05/30 19:12
https://artmeetsjewellery.com/rooli-promotions-boost-your-business-growth-now/ https://artmeetsjewellery.com/rooli-promotions-boost-your-business-growth-now/: Excellent breakdown of the topic. 05/30 18:57
https://www.1337games.org/de-de/online-casino/neue/ https://www.1337games.org/de-de/online-casino/neue/: Взрослый доступен через гарантированные веб-сайты.... 05/30 16:51
https://luckycaponelogin.com/ https://luckycaponelogin.com/: Das lucky capone casino, lucky capone bietet Spiel... 05/30 16:31
https://captarnegocios.com/2026/05/29/rolling-slots-casino-games-fun-play-now/ https://captarnegocios.com/2026/05/29/rolling-slots-casino-games-fun-play-now/: Very well written post. 05/30 15:49
Services from s21g
YOMU Web小説リーダー
小説投稿サイトの公式ページを開き、WebView表示と読み上げ向け表示を切り替えて、移動中や作業中にもWeb小説の続きを聴きやすくするiPhoneアプリです。
補助探
公開されている補助金・助成金情報を集約し、条件に合う制度を探しやすくするサービスです。
jotter.me
個人開発者のためのホスティング一体型ノートサービス
ハンドミラー
iPhone向けの手鏡アプリ
ツイプロ(twpro)
Twitterプロフィールの高速検索エンジン