Authoritah update
I’ve pushed a couple of changes to my Authoritah gem recently that hope to make it a bit more useful. Firstly I’ve fixed using Procs that access the controller for testing whether an action is permitted or not:
class WidgetController < ApplicationController
forbids :current_user => Proc.new {|user| user.id == params[:id }
end
This now works as expected.
I have also added the ability to change the outcome of an authorisation failure rather than always returning a 404. You can now use the on_reject option to customise the behaviour, as follows:
class WidgetController < ApplicationController
permits :current_user => :logged_in?, :on_reject => :redirect_to_login
forbids :current_user => :blacklisted?,
:from => [:create, :destroy],
:on_reject => Proc.new { redirect_to '/blacklisted' }
def redirect_to_login
flash[:notice] = "Please login to view widgets"
redirect_to root_url
end
end
I hope these changes prove useful.
Advertisement