Ruby on Rails Tuesday, August 13, 2013

Hi. This is my first post.

First of all, I apologize my poor English. Actually, I'm not confident whether I can tell what I think, cause English is not my first language.

Anyway, I'm making online test program with Rails 3, based on Railscasts 196-197 nested form.

Though that episodes are out of dates, I could make it helped with stackoverflow and google.

The problem is taking examination form for students and auto grading system.

DB table is constructed like this.

survey -- question 1 -- answer 1
-- answer 2
-- answer 3
-- ...
-- question 2 -- answer 1
-- ...
-- ...

The idea is simple. In answer model, there are two boolean columns, correct and user_answer. Teacher can check correct answer while making examination, and students can check user_answer while taking examination.

In the view survey/show.html.erb I made another form for taking examination. After students fill the check box and pressed submit button, auto grading will be done, in grading method in survey controller. and finally they can see the result of test.

This is survey/show.html.erb It's working well.(I can see check box and label as I want) 

<h1><%= @survey.name %></h1>
 <%= form_tag({:controller => "surveys", :action => "grading"}) do %>
  <ol class="questions">
   <% @survey.questions.each do |question| %>
   <li>
   <%= question.content %>
     <ol class="answers">
     <% question.answers.each do |answer| %>
      <li>
        <%= check_box(answer.user_answer, answer)  %>
        <%= label("answer_".concat(answer.id.to_s).to_sym, answer.content) %>
      </li>
     <% end %>
     </ol>
   </li>
   <% end %>
  </ol>

  <div><%= submit_tag("Submit", :class => "submit") %></div>
<% end %>

but I'm not sure whether answer.user_answer can be saved correctly. because I can't make and see result pages.

I'm trying to use redirect_to method. For this, I wrote grading method in survey_controller

 def grading
    #@survey = Survey.find(params[:id])
    @survey = Survey.new

    redirect_to results_url
  end

and made survey/results.html.erb file(which contains result of test). but not working.

I put this line on config/routes.rb but still not working.
  match "surveys/grading" => "surveys#grading", :via => :post

Please let me know any idea related to this. 

Thanks, advanced.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/9e0cdc7e-8a5f-4471-ba33-07e12180b8b8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment