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
32
33
34
35
36
37
|
# 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
response = nil
begin
response = Response.find(request.session[:form_response])
rescue
response = nil
end
response
end
def find_or_create_response
response = nil
if find_response
response = find_response
else
response = Response.create
request.session[:form_response] = response.id
end
response
end
end
end
|