Module: Challah::Controller::ClassMethods

Defined in:
lib/challah/controller.rb

Instance Method Summary collapse

Instance Method Details

#restrict_to_authenticated(options = {}) ⇒ Object

Restrict the current controller to only users that have authenticated. All actions in the controller will be restricted unless otherwise stated. All normal options for a before_action are observed.

Examples:

class YourController < ApplicationController
  restrict_to_authenticated

  # ...
end

Restrict only the given actions

class YourOtherController < ApplicationController
  restrict_to_authenticated :only => [ :create, :update, :destroy ]

  # ...
end

See Also:

  • signin_required


31
32
33
34
35
36
37
38
39
40
41
# File 'lib/challah/controller.rb', line 31

def restrict_to_authenticated(options = {})
  block = proc { |controller| controller.send(:signin_required) }

  if respond_to?(:before_action)
    # Rails >= 4.0
    before_action(options, &block)
  else
    # Rails <= 3.2
    before_filter(options, &block)
  end
end

#signin_required(*args) ⇒ Object Also known as: login_required

Alias for restrict_to_authenticated



44
45
46
# File 'lib/challah/controller.rb', line 44

def (*args)
  restrict_to_authenticated(*args)
end