I'm making online test program with Rails 3.

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)

<%= @survey.name %>

<%= form_tag({:controller => “surveys”, :action => “grading”}) do %>

    <% @survey.questions.each do |question| %>

  1. <%= 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>
    
  2. <% end %>

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

<% 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.

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.

Don't worry, you are doing ok.

[snip]

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

To check whether it is being saved correctly first look in development.log, there you will see the sql commands and can check that the sql looks ok.

Also use a database command line or gui tool to look into the db directly to see whether the data are there.

Also have a look at the Rails Guide on debugging which will give you suggestions on how to debug your code.

Colin