Rails+deviseで稼働中のAPIに、ユーザー毎の権限設定を追加したい。 実装方法の背景 権限設定には大きく分けて2種類ある。と思う。 1.機能を制御するもの(主にcontrollerで制御する) 2.データを制御するもの(modelで制御しちゃいたい) 1はイメージしやすい。各APIを使う権限であり、controllerのメソッドを制御できれば良く、cancancan、pundit等のgemがある。 2は主に対象データのあるレコードが参照可能か、更新可能かを制御する。 例えば、ユーザーAは、itemモデルのid:1のデータを更新可で、id:2のデータは参照不可。ユーザーBはid:2だけ更新可のような。 2のようなデータ制御ができるgemを自分は知らない。そこで、current_userをmodelのdefault_scopeで使ってしまうことにした。 いや本当はcontroller
ネットサーフィンをしていると「CanCan便利!」「CanCanはRailsでの権限管理デファクトスタンダードだよ」などの声をぼちぼち見かけますが、あまりまとまったCanCanの使い方に関する記事を見つけられなかったので覚書をしたためます。 ほとんどCanCanの配布元Wikiに書いてあることですので、英語が読める方はそちらを参照するほうが正確だと思われます。 内容へのツッコミや訂正大歓迎です! CanCanとは (by CanCan repo README - github) CanCan is an authorization library for Ruby on Rails which restricts what resources a given user is allowed to access. All permissions are defined in a single
Google+ボタン はてなブックマークボタン 更新日時: 2015年08月16日(日) 作成日時: 2015年08月16日(日) 前の記事 / 次の記事 CanCanCanは便利そうだけど設定面倒くさそうなイメージがあって 使っていなかったのだけど、使ってみたら全然そんなことなかった。 CanCanCanというのは権限管理のためのgemで、 元々CanCanというgemがあって、その後継がCanCanCan。 参考 CanCanCommunity/cancancan How to use CanCan / CanCanCan 何ができるのか? 例えば if can? :update, @article =from_for @article do |f| =f.text_field :name =f.textarea :content if cannot? destroy, @articl
May 25, 2015CanCanCan: The Rails Authorization Dance Recently, I have written an overview of some popular authentication solutions for Rails. However, in many cases, having authentication by itself is not enough – you probably need an authorization mechanism to define access rules for various users. Is there an existing solution, preferably one that isn’t very complex, but is still flexible? Meet
最近初めて、Rails内だけでユーザーの管理、ログインをする機能を実装しました。簡単にネットで調べた限りでは、『devise』と『cancancan』を使う方法が一番シンプルでしっくりきました。 こういった一般的な機能を実装するときにはRailsには本当に多様なライブラリがあるのが強みだなとつくづく感じます! (07-02 21:55) 設定の追記やlocaleファイルのダウンロードなどを追記 🎂 次試すメモ『mcasimir/devise-i18n-views』で翻訳したdeviseのviewを生成できそう。次試してみます! 🍮 GemのインストールGemfileに次のコードを追加して、bundle installを実行。
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く