2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'app/controllers/results_controller.rb', line 2
def index
@surveys = Survey.all
@survey = Survey.find(params[:survey_id])
@survey_answers = SurveyAnswer.where(:survey_id =>params[:survey_id])
@result = ActiveRecord::Base.connection.execute("
SELECT SUM(`points`) as `sum`
FROM
survey_answers `sa`
INNER JOIN answers `a`
ON `a`.`id` = `sa`.`answer_id`
WHERE `survey_id` = #{@survey.id};
").first
@summary_sql = ActiveRecord::Base.connection.execute("
SELECT summary
FROM `summaries`
WHERE `range_from` <= #{@result.sum}
AND `range_to` >= #{@result.sum}
")
@summary = @summary_sql.first.first
end
|