14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/controllers/forms_controller.rb', line 14
def update
@page = Page.find(params[:page_id]) rescue Page.first
@page.data = params
@page.request = OpenStruct.new({
:referrer => request.referer,
:session => session })
@form = Form.find(params[:id])
@form.page = @page
@response = find_or_create_response
@response.result = Forms::Config.deep_symbolize_keys(params)
begin
@form[:extensions] = Forms::Config.convert(@form.config)
rescue
raise "Form '#{@form.title}' has not been configured"
end
@results = {}
@form[:extensions].each do |name, config|
result = @form.call_extension(name,config)
@results.merge!({ name.to_sym => result })
session.merge!(result[:session]) if result[:session].present?
end
@response.result = @response.result.merge!({ :results => @results})
begin
@response.save!
redirect_to (@form.redirect_to.present? ? @form.redirect_to : (params[:redirect_to] || :back))
rescue
"Form '#{@form.title}' could not be submitted."
end
end
|