Skip to content

Commit

Permalink
Handle CanCan exceptions gracefully
Browse files Browse the repository at this point in the history
  • Loading branch information
augustf committed May 6, 2012
1 parent df36d6a commit cfd6415
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ def check_for_initial_install
end
end

#Don't break for CanCan exceptions; send the user to the front page with a Flash error message
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, :flash => { :notice => exception.message }
end

end
12 changes: 11 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
# See http://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.

en:
hello: "Hello world"
is_viewable: "Viewable"
is_submittable: "Submittable"
membership_approved: "Approved"
membersip_denied: "Denied"

#CanCan Exceptions localization (https://github.com/ryanb/cancan/wiki/exception-handling)
unauthorized:
read:
all: "You're not authorized to read %{subject}."
create:
all: "You're not authorized to create %{subject}."
update:
all: "You're not authorized to update %{subject}."
delete:
all: "You're not authorized to delete %{subject}."

0 comments on commit cfd6415

Please sign in to comment.