Add ClientAbility
This commit is contained in:
parent
bb5a4019e6
commit
321d0ea716
5 changed files with 25 additions and 3 deletions
2
Gemfile
2
Gemfile
|
@ -82,3 +82,5 @@ group :production do
|
||||||
end
|
end
|
||||||
|
|
||||||
gem 'high_voltage', '~> 2.4.0'
|
gem 'high_voltage', '~> 2.4.0'
|
||||||
|
|
||||||
|
gem 'simple_form'
|
||||||
|
|
|
@ -217,6 +217,9 @@ GEM
|
||||||
select2-rails (3.5.9.3)
|
select2-rails (3.5.9.3)
|
||||||
thor (~> 0.14)
|
thor (~> 0.14)
|
||||||
sexp_processor (4.6.0)
|
sexp_processor (4.6.0)
|
||||||
|
simple_form (3.1.1)
|
||||||
|
actionpack (~> 4.0)
|
||||||
|
activemodel (~> 4.0)
|
||||||
spring (1.3.6)
|
spring (1.3.6)
|
||||||
sprockets (3.3.4)
|
sprockets (3.3.4)
|
||||||
rack (~> 1.0)
|
rack (~> 1.0)
|
||||||
|
@ -276,6 +279,7 @@ DEPENDENCIES
|
||||||
sass-rails (~> 5.0)
|
sass-rails (~> 5.0)
|
||||||
sdoc (~> 0.4.0)
|
sdoc (~> 0.4.0)
|
||||||
select2-rails
|
select2-rails
|
||||||
|
simple_form
|
||||||
spring
|
spring
|
||||||
sqlite3
|
sqlite3
|
||||||
turbolinks
|
turbolinks
|
||||||
|
|
|
@ -6,4 +6,12 @@ class ApplicationController < ActionController::Base
|
||||||
rescue_from CanCan::AccessDenied do |exception|
|
rescue_from CanCan::AccessDenied do |exception|
|
||||||
redirect_to root_url, alert: exception.message
|
redirect_to root_url, alert: exception.message
|
||||||
end
|
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
|
end
|
||||||
|
|
8
app/models/client_ability.rb
Normal file
8
app/models/client_ability.rb
Normal 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
|
|
@ -1,6 +1,6 @@
|
||||||
= @transaction.errors.full_messages.join(", ")
|
= @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.collection_select :creditor_id, User.all, :id, :name, {}, { class: 'select2-selector' }
|
||||||
= f.number_field :amount
|
= f.input :amount
|
||||||
= f.text_field :message, required: true
|
= f.input :message, required: true
|
||||||
= f.submit "Send it!"
|
= f.submit "Send it!"
|
||||||
|
|
Loading…
Reference in a new issue