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://slon8.at-slon6.cc https://slon8.at-slon6.cc: Superb, what a webpage it is! This weblog presents... 04/15 21:27
https://wikzaim.ru/ https://wikzaim.ru/: Если деньги нужны срочно нет желания тратить время... 04/15 18:58
https://severlight.su:443/bitrix/redirect.php?goto=https://puertadelsolsanblas.com.ar/3-super-hot-chillies-slot-spicy-reels-and-sizzling-wins/ https://severlight.su:443/bitrix/redirect.php?goto=https://puertadelsolsanblas.com.ar/3-super-hot-chillies-slot-spicy-reels-and-sizzling-wins/: I was curious if you ever thought of changing the ... 04/15 16:00
https://tkoutlet.co.kr https://tkoutlet.co.kr: Hi, I do think this is an excellent web site. I st... 04/15 15:25
https://tkoutlet.co.kr https://tkoutlet.co.kr: Have you ever considered about including a little ... 04/15 15:24
https://tkoutlet.co.kr/%ec%8b%a0%ec%9a%a9%ec%b9%b4%eb%93%9c%ed%98%84%ea%b8%88%ed%99%94%ea%b5%ac%ec%a1%b0%ec%a0%95%eb%a6%ac%ec%86%8c%ec%95%a1%ea%b2%b0%ec%a0%9c%ed%98%84%ea%b8%88%ed%99%94%eb%8b%b9%ec%9d%bc%ec%9e%85%ea%b8%88/ https://tkoutlet.co.kr/%ec%8b%a0%ec%9a%a9%ec%b9%b4%eb%93%9c%ed%98%84%ea%b8%88%ed%99%94%ea%b5%ac%ec%a1%b0%ec%a0%95%eb%a6%ac%ec%86%8c%ec%95%a1%ea%b2%b0%ec%a0%9c%ed%98%84%ea%b8%88%ed%99%94%eb%8b%b9%ec%9d%bc%ec%9e%85%ea%b8%88/: Hi there! I could have sworn I've been to this web... 04/15 14:55
https://searchpg.com/author/bradlysilverma/ https://searchpg.com/author/bradlysilverma/: The analytics on the sumex official website are ... 04/15 14:51
https://tanzypropertybury.co.uk/author/brooksbilodeau/ https://tanzypropertybury.co.uk/author/brooksbilodeau/: Sumex makes it so much easier to bridge assets bet... 04/15 14:43