Code help for implementing online exam please

Hi, I have been trying to write code for making an online exam
management system. I could not think about a logic to implement the
actual exam.
Here is the problem:
I have a questions table with fields like- id, question, opt1, opt2,
opt3, opt4 and correctans.
I want to read all the records from this table but I want to display
only one record at a time for user to answer the question. User then
clicks next to see the next question and choices and so on till the end
of the records.
I don’t know how to implement this. I did
@questions=Question.find(:all)
Now how can I use this @questions and display only one record at a time
so that user answers the question and then I can do something to store
the user response?

OR if I am wrong, please suggest good logic to implement this.

Thanks

First of all, online exam must be have category of exam. each exam must
be up to date and never the same each date. out of your case i would
like to try my mind in this case now.


Class Question < ApplicationController

def start_page
#I use exam category_id in Questions table
#In this case I would like starting Rails Exam with category_id =2
#in Answer table should has column question_id, user_id, time_answer,
answer
#dont forget to store your user_id in session[:user_id]
#and set up in model for relational model or table.

if session[:id_questions]
@disable_button_answer = true
else
@all_question = Question.find(:all, :conditions=>[‘category_id=?’, 2])
session[:id_questions] = @questions.map(&:id)
@first_question = @all_question.first
@user_answer = Answer.new
end

end

#here method for user answer question
def answer
@used_id = [] << params[:user_answer][:question_id]
params[:user_answer][:user_id]= session[:user_id]
params[:user_answer][:time_answer]= Time.now
@user_answer = Answer.new(params[:user_answer])

if @user_answer.save
session[:id_questions] = session[:id_questions] - @used_id
if session[:id_questions].blank?
redirect_to :action=> :complete_page
else
redirect_to :action=> :next_question, :id=>
session[:id_questions].first, :last_page_id => @used_id
end
end
end

def next_question
@question = Question.find(params[:id])
@user_answer = Answer.new
@back_page = params[:last_page_id]
@next_page = session[:id_questions][1]
end


Suggestion :

  • For button NEXT PAGE in Question PaGe, put use params next_page and
    use this params in metod for showing NEXT PAGE to identify next
    question.
  • The rule is up to you, what you want disable button answer if user use
    next or back page button and store it in database such as an Un-answer
    page or else.

Peace Regards,
Y. Reinhart A P
Blog : teapoci.blogspot.com

Rails T. wrote:

Rails T. wrote:
if @user_answer.save
session[:id_questions] = session[:id_questions] - @used_id
if session[:id_questions].blank?
redirect_to :action=> :complete_page
else
redirect_to :action=> :next_question, :id=>
session[:id_questions].first, :last_page_id => @used_id
end

the correct is :

redirect_to :action=> :next_question, :id=>
session[:id_questions].first[0], :last_page_id => @used_id[0]

if you find any error, keep post it, I will review back when I’m online.
:slight_smile:

I hope some my brothers can develop my code and give good suggestion
from my code or maybe can provide new code. :slight_smile:

Have nice weekend
Y. Reinhart A P
Blog : teapoci.blogspot.com

Rails T. wrote:

Rails T. wrote:

Rails T. wrote:
if @user_answer.save
session[:id_questions] = session[:id_questions] - @used_id
if session[:id_questions].blank?
redirect_to :action=> :complete_page
else
redirect_to :action=> :next_question, :id=>
session[:id_questions].first, :last_page_id => @used_id
end

the correct is :

redirect_to :action=> :next_question, :id=>
session[:id_questions].first[0], :last_page_id => @used_id[0]

if you find any error, keep post it, I will review back when I’m online.
:slight_smile:

I hope some my brothers can develop my code and give good suggestion
from my code or maybe can provide new code. :slight_smile:

Have nice weekend
Y. Reinhart A P
Blog : teapoci.blogspot.com

Thank you brother. You helped me a lot. I did it…
Actually I was implementing someting too simple with single table for
practice. But now I will use multiple tables with relations and a real
working implementation.

Thanks
Great job. Keep doing.

Rails T. wrote:

if @user_answer.save
session[:id_questions] = session[:id_questions] - @used_id
if session[:id_questions].blank?
redirect_to :action=> :complete_page
else
redirect_to :action=> :next_question, :id=>
session[:id_questions].first, :last_page_id => @used_id
end

the correct is :

redirect_to :action=> :next_question, :id=>
session[:id_questions].first, :last_page_id => @used_id[0]

if you find any error, keep post it, I will review back when I’m online.
:slight_smile:

I hope some my brothers can develop my code and give good suggestion
from my code or maybe can provide new code. :slight_smile:

Have nice weekend
Y. Reinhart A P
Blog : teapoci.blogspot.com

hi iwant to send a session variable to the database,can you please
tell me how can
i do that

On Sep 27, 9:08 am, Rup R. [email protected]