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 823013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:53:04+00:00 2026-05-15T02:53:04+00:00

I’m trying to grade a quiz application I would like to make. I have

  • 0

I’m trying to grade a quiz application I would like to make. I have a questions model with and ask(the actual question), 4 choices(a-d), and a correct answer(string).

In the view I have the 4 question being diplayed then the correct answer choice (This is just a test for functionality) and then I created a text_field to accept the users answer choice and a button to refresh the index action which has the scoring logic, for now..

–Do I need to put the text_field within a form_tag?

<p>1. <%= h @question.q1  %></p>
<p>2. <%= h @question.q2  %></p>
<p>3. <%= h @question.q3  %></p>
<p>4. <%= h @question.q4  %></p>
<p>Answer: <%= h @question.correct  %></p>
<%= text_field_tag :choice, params[:choice] %> 
<%= button_to "Grade", {:controller => 'site', :action => "index"}  %> 
<p> <%= @answer %></p>

Heres the index controller action

def index 
      @question = Question.find(1) 
         if @question.correct == params[:choice]
             @answer = 'right'
         else
                @answer = 'wrong'
         end
end

Its not really working. The textfield is supposed to take a letter choice like ‘a’ or ‘c’ and compare it with the correct answer in the database.

I would love this to work by radiobuttons, but I’m a newbie to rails so I thought I’d take baby steps.

So if anyone can help me with how to fix this by string, or preferably by radiobuttons, I’d really appreciate it.

  • 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-15T02:53:05+00:00Added an answer on May 15, 2026 at 2:53 am

    Here’s how I would do it:

    # in app/controller/QuestionsController
    def index 
      @question = Question.find(1) 
      @grade = params[:choice] == @question.answer ? 'PASS' : 'FAIL'
    end
    

    It will require a named route in your config/routes.rb file:

    map.questions 'questions', :controller => 'questions', :action => 'index'
    

    and then, in app/views/index.html.erb:

    <h2><%=h @question.question_text %></h2>
    
    <ol>
      <li><%=h @question.q1 %></li>
      <li><%=h @question.q2 %></li>
      <li><%=h @question.q3 %></li>
      <li><%=h @question.q4 %></li>
    </ol>
    
    <p>
      Correct answer <%=h @question.correct %>
    </p>
    
    <% form_tag do %>
      <p>Choice? <%= text_field_tag :choice %></p>
      <%= submit_tag 'Grade' %>
    <% end %>
    
    <p>Grade: <%= @grade %></p>
    

    I could give you much more specific assistance if you’d provide your routes.rb file as well as the rest of your controller code. The above answer is not RESTful at all. If that is at all important to you, the routes configuration would be different, as well as the controller code. Also, with RESTful design, you could use a form_for method call in your view, which is more standard these days.

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

Sidebar

Related Questions

No related questions found

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.