Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4577742
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:23:18+00:00 2026-05-21T20:23:18+00:00

#online_exam_controller class OnlineExamController < ApplicationController def index @user=current_user @employee=Employee.find_by_employee_number(@user.username) # flash[:notice]=#{@employee.id} @subjects=EmployeesSubject.find_all_by_employee_id(@employee.id) @subject_name=[] @batch_details=[]

  • 0
#online_exam_controller
class OnlineExamController < ApplicationController
   def index
    @user=current_user
    @employee=Employee.find_by_employee_number(@user.username)
    # flash[:notice]="#{@employee.id}"
    @subjects=EmployeesSubject.find_all_by_employee_id(@employee.id)
    @subject_name=[]
    @batch_details=[]
    @display_details=[[]]
    @count=0
    for @t in @subjects
     @subject_name[@count]=Subject.find(@t.subject_id,:select=>'name,code,batch_id')
     @batch_details[@count]=Batch.find(@subject_name[@count].batch_id,:select =>'name')
     @display_details[@count][0]=@subject_name[@count].name+" "+@batch_details[@count].name
     @display_details[@count][1]=@t.subject_id
     @count+=1
    end
   end
   def show
    if params[:subject_id]==''
     @question_type=[]
    else
     @question_type=['multiple_choice','fill_ups','matches','descriptive']
     @subject_id=params[:subject_id]

   end
   respond_to do |format|
   format.js {render:action=>'show' }
   end
  end
  def new_multiple_choice
   @quiz=MultipleChoiceQuestion.new
   @subject=Subject.find params[:id] if request.xhr? and params[:id]
   respond_to do |format|
    format.js {render :action => 'new_multiple_choice'}
   end
  end
 end
#index.html.erb
<div id="content-header">
<img src="/images/show_settings.png" alt="Subjects"/>
<h1>Subjects</h1>
<h3>Home</h3>
 <div id="app-back-button">
 <%= link_to_function image_tag("/images/buttons/back.png",:border => 0), "history.back()" %>
 </div>
 </div>

 <div id="page-yield">
 <% unless flash[:notice].nil? %>
 <p class="flash-msg"> <%= flash[:notice] %> </p>
 <% end %>
 <div class="box">

  <div class="label-field-pair">
  <label for="student_course">Select a batch:
  <%= image_tag("loader.gif",:align => "absmiddle",:border => 0,:id => "loader", :style =>"display: none;" ) %>
  </label>
  <div class="text-input-bg">
  <%= select :subject,:id,
   @display_details.map {|b| [b[0],b[1]]},
  {:prompt => 'selecct subject'},
  {:onchange =>"#{remote_function(
  :url=>{:action => 'show'},
  :before=> "Element.show('loader')",
  :success => "Element.hide('loader')" )}"}%>

  </div></div>

  <div id="subjects"></div>
  <div id="modal-box" style="display:none;"></div>

  <div class="extender"></div>
  </div></div>
  #show.rjs
  if @question_type.empty?
   page.replace_html 'subjects', :partial => 'question_bank'
  else
   page.replace_html 'subjects', :partial => 'question_bank'
  end
  #_question_bank.html.erb
  <% unless @question_type.nil? %>
   <div class="add_sub">
   <%= link_to_remote 'Add Multiple Question ', :url => { :action =>   'new_multiple_choice', :id => @subject_id } %>
   </div>
   <div class="add_sub">
    <%= link_to_remote 'Add Fill Up Question', :url => { :action => 'new_fill_ups', :id => @subject_id } %>
   </div>
   <div class="add_sub">
   <%= link_to_remote 'Add Match Question', :url => { :action => 'new_matches', :id => @subject_id } %>
   </div>
   <div class="add_sub">
   <%= link_to_remote 'Add Descriptive Question', :url => { :action => 'new_descriptive', :id => @subject_id } %>
   </div>
   <% end %>
  #new_multiple_choice.rjs
  page.replace_html 'modal-box', :partial => 'new_multiple_choice'
  page << "Modalbox.show($('modal-box'), {title: 'Add new multiple choice questions', width: 500});"
   #_new_multiple_choice.html.erb

   <div id="grading-levels-form">
   <h4><%= @subject.name unless @subject.nil? %></h4>

   <% form_remote_for @quiz do |f| %>

    <% subject_id = (@subject.nil? ? nil : @subject.id) %>
    <% batch_id = (@subject.nil? ? nil : @subject.batch_id ) %>
    <%= f.hidden_field :batch_id, :value => batch_id %>
    <%= f.hidden_field :subject_id, :value => elective_group_id %>

     <div id="form-errors"></div>

     <div class="label-field-pair">
     <div class="label-container"><%= f.label :question %></div>
     <div class="input-container"> <%= f.text_field :question %></div>
     </div>
     <div class="label-field-pair">
     <div class="label-container"><%= f.label :answer1 %></div>
     <div class="input-container"> <%= f.text_field :answer1 %></div>
     </div>
     <div class="label-field-pair">
     <div class="label-container"><%= f.label :answer2 %></div>
     <div class="input-container"> <%= f.text_field :answer2 %></div>
     </div>
     <div class="label-field-pair">
     <div class="label-container"><%= f.label :answer3 %></div>
     <div class="input-container"> <%= f.text_field :answer3 %></div>
     </div>
     <div class="label-field-pair">
     <div class="label-container"><%= f.label :answer4 %></div>
     <div class="input-container"> <%= f.text_field :answer4 %></div>
     </div>

     <div class="label-field-pair">
     <div class="label-container"> <%= f.label :correct_option %></div>
     <div class="input-container"><%= f.select (:correct_option,%w{1,2,3,4}) %></div>
     </div>



     <%= f.submit "", :value => "► Save", :class => "submit_button" %>

     <% end %>
     </div>
     #server log
     Processing OnlineExamController#show (for 127.0.0.1 at 2011-04-05 19:31:00) [POST]
     Parameters: {"action"=>"show",      "authenticity_token"=>"OXozxkL1y+gCKkWxsUbAR8nH9Cb8MJJJPtnEVw8Y1AI=", "controller"=>"online_exam"}
     User Columns (0.8ms) SHOW FIELDS FROM `users`
     User Load (0.1ms) SELECT * FROM `users` WHERE (`users`.`id` = 8)
     CACHE (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 8)
      Rendering online_exam/show
      Rendered online_exam/_question_bank (5.6ms)
      Completed in 21ms (View: 8, DB: 3) | 200 OK [http://localhost/online_exam/show]
       SQL (4.7ms) SET SQL_AUTO_IS_NULL=0


      Processing OnlineExamController#show (for 127.0.0.1 at 2011-04-05 19:31:02)      [POST]
       Parameters: {"action"=>"show",   "authenticity_token"=>"OXozxkL1y+gCKkWxsUbAR8nH9Cb8MJJJPtnEVw8Y1AI=", "controller"=>"online_exam"}
     User Columns (1.0ms) SHOW FIELDS FROM `users`
     User Load (0.8ms) SELECT * FROM `users` WHERE (`users`.`id` = 8)
     CACHE (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 8)
     Rendering online_exam/show
     Rendered online_exam/_question_bank (5.6ms)
     Processing OnlineExamController#new_multiple_choice (for 127.0.0.1 at 2011-04-05 19:31:04) [POST]
     Parameters: {"action"=>"new_multiple_choice",   "authenticity_token"=>"OXozxkL1y+gCKkWxsUbAR8nH9Cb8MJJJPtnEVw8Y1AI=",  "controller"=>"online_exam"}
     User Columns (1.1ms) SHOW FIELDS FROM `users`
     User Load (0.1ms) SELECT * FROM `users` WHERE (`users`.`id` = 8)
     CACHE (0.0ms) SELECT * FROM `users` WHERE (`users`.`id` = 8)
       MultipleChoiceQuestion Columns (1.0ms) SHOW FIELDS FROM     `multiple_choice_questions`
     Completed in 22ms (View: 2, DB: 2) | 200 OK [http://localhost/online_exam/new_multiple_choice]
       SQL (0.1ms) SET SQL_AUTO_IS_NULL=0 here

I know code is very long and been breaking my head for hours,My problem _new_multiple_choice.html.erb is not rendered when i click the first link at the end.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:23:19+00:00Added an answer on May 21, 2026 at 8:23 pm

    Most Rubyists would be horrified by this code and run away. Instead of answering your question (which, if solved, would make your app even more horrific), here are some basics; do these so you can start asking questions that people would answer.

    Rails does most of the work for you so you don’t have to find relationships with ids or set arrays up yourself. Instance variables are used to pass things on to the view. Try to pass the view exactly what it needs and no more.

    First, set up your relationships with the models…

    models/user.rb

    class User
      has_one :employee
    end
    

    models/employee.rb

    class Employee
      belongs_to :user
      has_and_belongs_to_many :employee_subjects
    end
    

    models/employee_subject.rb

    class EmployeeSubject
      has_and_belongs_to_many :employees
      has_one :batch
    end
    

    models/batch.rb

    class Batch
      belongs_to :employee_subject
    end
    

    has_and_belongs_to_many is a bit tricky, so read the docs carefully:
    http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_and_belongs_to_many

    Then you can simplify your controller actions to one line…

    controllers/online_exams_controller.rb

    def index
      @subjects = current_user.employee.employee_subjects
    end
    

    and in your views…

    views/online_exams/index.html.erb

    <ul>
    <%= render :partial => '/subjects/list_view', :collection => @subjects, :as => :subject %>
    </ul>
    

    views/employee_subjects/_list_view.html.erb

    <li>
      Name: <%= subject.name -%>, Code: <%= subject.code -%>,
      Batch Name: <%= subject.batch.name -%>
    </li>
    

    Before you do any more though, think through how your application’s objects should be organised and related, and try to use names that make sense. Read more about object-oriented programming concepts, and follow some Rails tutorials, and get used making apps with 10 times fewer lines of code!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing an online exam portal, so that a user can start the
Had to write the following program for an on line pre java class using,
Most online games arbitrarily form teams. Often times its up to the user, and
Online Image Editor - Ajax or Flex / Flash? The above wasn't really the
Java integrates nicely with the user's desktop OS through JNLP. Not only does my
This is for an online form for product returns. The user selects from a
My webapplication is online exam site. when user click on start for writing test,
My online store uses local storage to store the cart. After the user has
For an online examination system, user actions/answers to be stored and later retrieved if
http://docs.google.com/gview?a=v&q=cache:spO3YR6dNcoJ:www.sqa.org.uk/sqa/files/hn/F6C135.pdf My class has just been discussing the course descriptor for the SQA Higher

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.