LoginSignup
3
3

More than 5 years have passed since last update.

cancanをいじってみた

Posted at

cancanというgemを入れようかと思っていじってみた。(結果入れなかったけど)

RailsCastのライアンさんが作ったgemで、例によって、RailsCastがわかりやすい。
http://railscasts.com/episodes/192-authorization-with-cancan

日本語の資料はこちら。
https://sites.google.com/site/railssiryou/gem/192-authorization-with-cancanwo-yi-denamono

cancan使ってみた例。
http://blog.udzura.jp/2012/01/12/lovely-authorization-with-cancan/

このあたりを見て、ちょっと中のソースを見れば、どんな感じかがわかると思います。

initialize(user)して、Userモデル使って、
roleを設定して、そのrole毎にできることとか設定していく感じみたい。

閲覧者や書き手、編集者、などroleがたくさんある場合に使うと捗るgemだと思った。

今回は、roleそんなになかったので、controllerに書いて、gemは使いませんでした。
また機会があれば!

追記
Rails4で使う場合は、

$ gem "cancan", :git => "git://github.com/ryanb/cancan.git", :branch => "2.0"
で使う。
こちらを見るに対応がやや怪しいぽい。
http://blog.n-z.jp/blog/2013-10-08-rails4-authorization.html

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3