Module: Forms::Controllers::ApplicationController

Defined in:
lib/forms/controllers/application_controller.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/forms/controllers/application_controller.rb', line 5

def self.included(base)
  base.class_eval do
    def current_response
      return @current_response if defined?(@current_response)
      @current_response = find_or_create_response if request.session[:form_response]
    end
    
    def find_response
      begin
        response = Response.find(request.session[:form_response])
      rescue
        response = nil
      end
    end
    
    def find_or_create_response
      if find_response
        response = find_response
      else
        response = Response.create
        request.session[:form_response] = response.id
      end
      
      response
    end
  end
end