Add ClientAbility

This commit is contained in:
benji 2015-09-09 11:24:45 +02:00
parent bb5a4019e6
commit 321d0ea716
5 changed files with 25 additions and 3 deletions

View file

@ -82,3 +82,5 @@ group :production do
end
gem 'high_voltage', '~> 2.4.0'
gem 'simple_form'

View file

@ -217,6 +217,9 @@ GEM
select2-rails (3.5.9.3)
thor (~> 0.14)
sexp_processor (4.6.0)
simple_form (3.1.1)
actionpack (~> 4.0)
activemodel (~> 4.0)
spring (1.3.6)
sprockets (3.3.4)
rack (~> 1.0)
@ -276,6 +279,7 @@ DEPENDENCIES
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
select2-rails
simple_form
spring
sqlite3
turbolinks

View file

@ -6,4 +6,12 @@ class ApplicationController < ActionController::Base
rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, alert: exception.message
end
def current_ability
if current_user
@current_ability ||= Ability.new(current_user)
elsif current_client
@current_ability ||= ClientAbility.new(current_account)
end
end
end

View file

@ -0,0 +1,8 @@
class Ability
include CanCan::Ability
def initialize(client)
client ||= Client.new # guest user (not logged in)
can :manage, :all
end
end

View file

@ -1,6 +1,6 @@
= @transaction.errors.full_messages.join(", ")
= form_for @transaction do |f|
= simple_form_for @transaction do |f|
= f.collection_select :creditor_id, User.all, :id, :name, {}, { class: 'select2-selector' }
= f.number_field :amount
= f.text_field :message, required: true
= f.input :amount
= f.input :message, required: true
= f.submit "Send it!"