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

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

インストール方法

config/environment.rbに

   1    config.gem "thoughtbot-clearance", 
   2      :lib     => 'clearance', 
   3      :source  => 'http://gems.github.com',
   4      :version => '>= 0.5.3'

config/environments/test.rbに

   1  config.gem 'thoughtbot-shoulda',
   2    :lib     => 'shoulda',
   3    :source  => "http://gems.github.com", 
   4    :version => '>= 2.10.0'
   5  config.gem 'thoughtbot-factory_girl',
   6    :lib     => 'factory_girl',
   7    :source  => "http://gems.github.com", 
   8    :version => '>= 1.2.0'

と記述し、

   1  % sudo rake gems:install
   2  % sudo rake gems:install RAILS_ENV=test

あとは、

   1  % ./script/generate clearance

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

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

   1  DO_NOT_REPLY = 'do_not_reply@s21g.com'

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

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

   1  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 Png genki on Mon 16 Mar 2009 at 16:00

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1365
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ