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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:45:57+00:00 2026-06-13T14:45:57+00:00

I built an view to create question and answer. This is my Question and

  • 0

I built an view to create question and answer. This is my Question and Answer model:

class Question < ActiveRecord::Base
  attr_accessible :content

  belongs_to :topic
  belongs_to :user
  belongs_to :question_type
  has_many :answers, dependent: :destroy
  accepts_nested_attributes_for :answers
end

class Answer < ActiveRecord::Base
  attr_accessible :content

  belongs_to :question
end

My answer model also have a attribute called correct type boolean to set true if which answer is correct, default is false. I have built a form to create a True/False question:

<%= simple_form_for @question do |q| %>

  <%= q.input :content, input_html: { rows: 3, class: 'span6' } %>
  <%= q.input :mark, input_html: { class: 'span1' } %>
  <%= q.association :topic %>
  <%= q.association :question_type %>

  <%= q.simple_fields_for :answers do |a| %>

    <%= a.input :correct, collection: [[true, 'True'], [false, 'False']],
                                                            as: :radio_buttons,
                                                            label: 'Answer',
                                                            value_method: :first,
                                                            label_method: :last,
                                                            item_wrapper_class: 'inline'
                                                            %>

  <% end %>
<% end %>

The correct attribute when rendered in view have these html:

<label class="radio inline"><input class="radio_buttons optional" id="question_answers_attributes_0_correct_true" name="question[answers_attributes][0][correct]" type="radio" value="true">True</label>

<label class="radio inline"><input checked="checked" class="radio_buttons optional" id="question_answers_attributes_0_correct_false" name="question[answers_attributes][0][correct]" type="radio" value="false">False</label>

Now in controller i want to check which radio button is checked and its value. Is there any method to check if correct attribute is checked and its value in controller?

  • 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-06-13T14:45:58+00:00Added an answer on June 13, 2026 at 2:45 pm

    You have to iterate over the params[:question][:answers_attributes] to check radio button checked or not. You can do something like this,

    params[:question][:answers_attributes].collect do |answer_attribute|
         answer_attribute if answer_attribute.last["correct"] == true
    end.compact
    

    This will return an array of answer attributes which are corrected as true.

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

Sidebar

Related Questions

i've built a BaseAdapter extended class for my list view.. inside i have a
(From the point of view of a user, not how it's built or which
I currently have a DetailView for Django's built-in User . url( r'^users/(?P<pk>\d+)/$', DetailView.as_view( model
I have an odd question. Let's assume I create something using scaffolding. This should
I've a question related to some C# implementation on Model-View-Controller. I am fairly new
I've looked at every question so far and none seem to actually answer this
In our build , we use to delete our view and create new view
I create a custom right view as follows: // Build the Segmented Control NSArray
‘ Servers ’ is built-in view in Eclipse. We could integrate Java EE server
I've built a simple customized view and registered onClickListener() in a constructor. To start

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.