Class: AuthHelpers::Controller::Confirmable

Inherits:
ApplicationController
  • Object
show all
Includes:
Helpers, InheritedResources::BaseHelpers
Defined in:
lib/auth_helpers/controller/confirmable.rb

Instance Method Summary collapse

Methods included from Helpers

included

Instance Method Details

#create(&block) ⇒ Object Also known as: create!

POST /account/confirmation POST /account/confirmation.xml



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/auth_helpers/controller/confirmable.rb', line 22

def create(&block)
  object = get_or_set_with_send(:find_and_resend_confirmation_instructions, params[self.instance_name])
  respond_block, redirect_block = select_block_by_arity(block)

  if object.errors.empty?
    set_flash_message!(:notice, 'We sent confirmation instructions to your email, please check your inbox.')

    respond_to_with_dual_blocks(true, block) do |format|
      format.html { redirect_to_block_or_scope_to(redirect_block, :session) }
      format.all  { head :ok }
    end
  else
    set_flash_message!(:error)
    options = { :with => object.errors, :status => :unprocessable_entity }

    respond_to_with_dual_blocks(false, block, options) do |format|
      format.html { render :action => 'new' }
    end
  end
end

#new(&block) ⇒ Object Also known as: new!

GET /account/confirmation/new



14
15
16
17
# File 'lib/auth_helpers/controller/confirmable.rb', line 14

def new(&block)
  object = get_or_set_with_send(:new)
  respond_to(:with => object, &block)
end

#show(&block) ⇒ Object Also known as: show!



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/auth_helpers/controller/confirmable.rb', line 46

def show(&block)
  object = get_or_set_with_send(:find_and_confirm, params[self.instance_name])
  respond_block, redirect_block = select_block_by_arity(block)

  if object.errors.empty?
    set_flash_message!(:notice, '{{resource_name}} was successfully confirmed.')

    respond_to_with_dual_blocks(true, block) do |format|
      format.html { redirect_to_block_or_scope_to(redirect_block, :session) }
      format.all  { head :ok }
    end
  else
    set_flash_message!(:error, object.errors.on(:perishable_token))
    options = { :with => object.errors, :status => :unprocessable_entity }

    respond_to_with_dual_blocks(false, block, options) do |format|
      format.html { redirect_to :action => 'new' }
    end
  end
end