From ed2e73832d1aafad5383e5742bf855bfdc6ca9cc Mon Sep 17 00:00:00 2001 From: Skud Date: Fri, 1 Feb 2013 11:10:12 +1100 Subject: [PATCH] sorta kinda works, but login/homepage are b0rked --- app/controllers/application_controller.rb | 8 +++++++- app/controllers/crops_controller.rb | 1 + app/models/ability.rb | 6 +----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 42f566de4..7b9467a97 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,15 @@ class ApplicationController < ActionController::Base protect_from_forgery + load_and_authorize_resource # tweak CanCan defaults because we don't have a "current_user" method def current_ability - @current_ability ||= AccountAbility.new(current_member) + @current_ability ||= Ability.new(current_member) end + # CanCan error handling + rescue_from CanCan::AccessDenied do |exception| + redirect_to root_url, :alert => exception.message + end + end diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index f8074c2d5..648fde43a 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -1,4 +1,5 @@ class CropsController < ApplicationController + # GET /crops # GET /crops.json def index diff --git a/app/models/ability.rb b/app/models/ability.rb index 7f5a533ca..d80864758 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -3,13 +3,11 @@ class Ability def initialize(member) # See the wiki for details: https://github.com/ryanb/cancan/wiki/Defining-Abilities - member ||= Member.new # guest member (not logged in) # everyone can do these things, even non-logged in can :read, :all - if member.logged_in? - + if member # managing your own user settings can :update, Member, :id => member.id @@ -36,8 +34,6 @@ class Ability can :create, Planting can :update, Planting, :garden => { :owner_id => member.id } can :destroy, Planting, :garden => { :owner_id => member.id } - end - end end