-
-
Save c0mrade/aa2b034666e1b334ae30 to your computer and use it in GitHub Desktop.
Revisions
-
Marc created this gist
Jun 5, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ class Ability include CanCan::Ability def marshal_dump #blocks cannot be cached @rules.reject{|rule| rule.instance_variable_get :@block }.map{|rule| Marshal.dump(rule) } end def marshal_load array #blocks cannot be cached, so blocks must be re-defined can :read, Comment do |comment| comment.length > 100 end @rules += array.map{|rule| Marshal.load(rule) } end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ class ApplicationController < ActionController::Base if !Rails.env.development? def current_ability cached_ability = Rails.cache.read("#{current_user.cache_key}::ability") if cached_ability.present? ability = Marshal.load( cached_ability ) ability.user = current_user else ability = super Rails.cache.write("#{current_user.cache_key}::ability", Marshal.dump( ability )) end @current_ability = ability end end end