dimanche 29 mai 2016

Rails 'rapidfire' gem, is it possible to set a one chance limit per user for taking the survey/exam?

I´m trying to do this, but I can´t find out how to:(

I´m creating a simple teachers/students plataform (a teacher creates exams online, a student take the exam(s)).

Everything seems to work with the gem, but the main porpose isn´t working, a student is not supposed to be able to answer a test several times. I´m not a rails expert of course, but I´d like if you´d guide me in the right direction.

My rapidfire questions_groups/index.html.erb has something like these(I think this is the important part)

<%= render partial: "question_group", collection: @question_groups%>

And my _questions_group.html.erb partial has this:

<tr id= "question_group_<%= question_group.id %>">
  <td>
    <% if can_administer? %>
      <%= link_to question_group.name, question_group_questions_path(question_group) %>
     <% else %>
      <%= question_group.name %>
    <% end %>
   </td>
<td>
  <ul class="horizontal-list">

  <!--######### My problem!!!!-->
  <% @answer_groups.each do |answer_group| %>
    <%if current_user.id!=answer_group.user_id&&answer_group.question_group_id!=question_group.id%>
       <li><%= link_to "Answer Questions", new_question_group_answer_group_path(question_group) %></li>
    <%end%>        
  <%end%>
  <!--#########-->

  <% if can_administer? %>
    <li><%= link_to "Results", [:results, question_group] %></li>
    <li><%= link_to "Delete", [question_group], method: :delete %></li>
  <% end %>
  </ul>
 </td>
</tr>

I thought about a solution, and iterated through that @answer_groups collection in order to know if the user has answered the question_group before, BUT I couldn't because I needed to define the collection, but I wasn´t able to properly pass it together with the @question_groups that is passed when the partial is rendered in the index.

I'd like some help please. Thank you!

Aucun commentaire:

Enregistrer un commentaire