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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'app/controllers/rails_vitals/playgrounds_controller.rb', line 10
def create
expression = params[:expression].to_s.strip
clean_expr = clean_expression(expression)
unless params[:confirmed] == "1"
@expression = clean_expr
@result = Playground::Sandbox::Result.new(
error: "Please confirm that you understand this runs real queries",
queries: [], query_count: 0, duration_ms: 0,
model_name: nil, record_count: 0, score: nil, n1_patterns: []
)
model_name = Playground::Sandbox.(clean_expr)
if model_name
@available_assocs = associations_for_model(model_name)
@prechecked_assocs = Array(params[:access_associations]).reject(&:blank?)
else
build_index_data
end
render :index
return
end
access_associations = Array(params[:access_associations]).reject(&:blank?)
result = Playground::Sandbox.run(
clean_expr,
access_associations: access_associations
)
model_name = Playground::Sandbox.(clean_expr)
@available_assocs = associations_for_model(model_name)
@prechecked_assocs = access_associations
@expression = clean_expr
@result = result
@previous = session_previous
@query_dna = build_dna(result.queries)
session[:playground_previous] = serialize_result(result, clean_expr, access_associations)
render :index
end
|