Skip to content

Instantly share code, notes, and snippets.

@EminenceHC
Created November 5, 2013 18:43
Show Gist options
  • Save EminenceHC/7323916 to your computer and use it in GitHub Desktop.
Save EminenceHC/7323916 to your computer and use it in GitHub Desktop.
Comparing Arrays
<h3>Result Sets</h3>
<div class="span12" style="width:100%;margin:5px;">
<% if current.loginable_type != 'Student' %>
<%= simple_form_for(result_sets_path, :method =>'get', :html => { :class => 'form-horizontal' }) do %>
<%= select_tag 'id', options_for_select(@quiz_id), { :prompt => 'Quiz Name'} %>
<%= select_tag 'student_id', options_for_select(@quiz_student_name), { :prompt => 'Student Name'} %>
<%= submit_tag 'Submit', :class => 'btn btn-primary' %>
<% end %>
<% end %>
<% @query.each do |a| %>
<table class="table table-condensed table-bordered table-striped table-responsive">
<tr>
<th>Student</th>
<th>Quiz</th>
<th>Survey ID</th>
<th>Result ID</th>
<th>Correct Answers</th>
<th>User Answers</th>
</tr>
</thead>
<tbody>
<tr>
<td><%= a.student.user.name %></td>
<td><%= a.survey.name %></td>
<td><%= a.survey_id %></td>
<td><%= a.id %></td>
<td><%= @actual %></td>
<td><%= @correct.collect{|x| "#{x}"} %></td>
<td><%= @score %></td>
</tr>
</tbody>
</table>
<% end %>
</div>
class ResultSetsController < ApplicationController
before_filter :new
def index
@surveys = Survey.all
@result_sets = ResultSet.all
@quiz_id = ResultSet.all.map { |u| [u.survey.name, u.id] }
@quiz_student_name = ResultSet.all.map { |u| [u.student.user.name, u.student_id]}
runquery = ResultSet
runquery = runquery.where(:id => params[:id]) if params[:id].present?
runquery = runquery.where(:student_id => params[:student_id]) if params[:student_id].present?
runquery = runquery.select('result_sets.*')
@query = runquery
@arr = []
@actual = []
@query.each do |a|
a.serial.to_a.each do |key,value|
@actual << value
end
a.survey.questions.each do |b|
@id = b.answers
@id.each do |c|
if c.correct == true
@correct = @arr << c.id
end
end
end
end
@score = @correct
end
def new
@result_set = ResultSet.new
end
def create
@result_set = ResultSet.new(result_set_params)
@result_set.save!
redirect_to result_sets_path, notice: "Quiz Completed Successfully"
end
def show
end
private
def result_set_params
params.require(:result_set).permit!
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment