Module: Cannie::ControllerExtensions::ClassMethods

Defined in:
lib/cannie/controller_extensions.rb

Instance Method Summary collapse

Instance Method Details

#check_permissions(options = {}) ⇒ Object

Method is used to be sure, that permissions checking is handled for each action inside controller.

class PostsController < ApplicationController
  check_permissions

  # ...
end


18
19
20
21
22
23
24
25
26
# File 'lib/cannie/controller_extensions.rb', line 18

def check_permissions(options = {})
  _if, _unless = options.values_at(:if, :unless)
  before_action(options.slice(:only, :except)) do |controller|
    next if controller.permitted?
    next if _if && !controller.instance_eval(&_if)
    next if _unless && controller.instance_eval(&_unless)
    current_permissions.permit!(controller.action_name, controller)
  end
end

#skip_check_permissions(*args) ⇒ Object

Skip handling of permissions checking, that was defined by ‘check_permissions` method

class PostsController < ApplicationController
  skip_check_permissions

  # ...
end


35
36
37
38
39
# File 'lib/cannie/controller_extensions.rb', line 35

def skip_check_permissions(*args)
  prepend_before_action(*args) do |controller|
    controller.instance_variable_set(:@_permitted, true)
  end
end