Betaal uw fucking schulden

This commit is contained in:
benji 2016-02-29 11:27:05 +01:00
parent 935049c1bf
commit 26973a330a
3 changed files with 15 additions and 5 deletions

View file

@ -2,7 +2,7 @@ class ApplicationController < ActionController::Base
protect_from_forgery with: :exception protect_from_forgery with: :exception
rescue_from CanCan::AccessDenied do |exception| rescue_from CanCan::AccessDenied do |exception|
redirect_to root_path, flash: { error: exception.message } redirect_to root_path, flash: { error: message_for(exception) }
end end
def after_sign_in_path_for(resource) def after_sign_in_path_for(resource)
@ -12,4 +12,14 @@ class ApplicationController < ActionController::Base
def after_sign_up_path_for(resource) def after_sign_up_path_for(resource)
root_path root_path
end end
private
def message_for exception
if exception.subject.class == Order && [:new, :create].include?(exception.action)
"Betaal uw fucking schulden!"
else
exception.message
end
end
end end

View file

@ -17,7 +17,7 @@ class Ability
def initialize_koelkast def initialize_koelkast
can :manage, Order do |order| can :manage, Order do |order|
!order.try(:user).try(:private) !order.try(:user).try(:private) && order.try(:user).try(:balance).try(:>, -500)
end end
can :quickpay, User can :quickpay, User
end end
@ -26,7 +26,7 @@ class Ability
can :read, :all can :read, :all
can :manage, User, id: user.id can :manage, User, id: user.id
can :create, Order do |order| can :create, Order do |order|
order.user == user order.user == user && user.try(:balance).try(:>, -500)
end end
can :destroy, Order do |order| can :destroy, Order do |order|
order.try(:user) == user && order.deletable order.try(:user) == user && order.deletable

View file

@ -12,8 +12,8 @@
%li.list-group-item %li.list-group-item
%strong Products ordered %strong Products ordered
%span.badge= @user.products_group_by_id.map(&:count).sum %span.badge= @user.products_group_by_id.map(&:count).sum
- if can? :create, @user.orders.build -# - if can? :create, @user.orders.build
%li.list-group-item= link_to "Place new order", new_user_order_path(@user), class: "btn btn-default btn-block" %li.list-group-item= link_to "Place new order", new_user_order_path(@user), class: "btn btn-default btn-block"
= render 'errors', object: @user = render 'errors', object: @user
- if can? :edit, @user - if can? :edit, @user
%ul.list-group %ul.list-group