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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:48:27+00:00 2026-06-10T01:48:27+00:00

Hi there I’m extremely new to Ruby and I’m currently working with two models

  • 0

Hi there I’m extremely new to Ruby and I’m currently working with two models and two corresponding databases. A Quiz which has_many questions. And I’m trying to get the questions to show up in the quiz “edit view” here’s what I have.

What currently is not working is the form entry for “questions” (see commented part below). I don’t think I understand the expressions preceded by the colons very well. (e.g. :title, :quiz_date etc>) are they regular variables?

Anyway, the block of code in question successfully makes a form but using :questions it puts all the information from the questions row of the database into to the form filed (i.e id, question, answer, possible answers, etc). But it doesn’t give me just the value of the question field.

But if I change it to :question (hoping to just get the value of the question field in the questions table) I get an error. I also tried :questions.question and just plain questions.question. None of these worked.

Any suggestions?

<%= form_for(@quiz) do |f| %>
<% if @quiz.errors.any? %>
<div id="error_explanation">
  <h2><%= pluralize(@quiz.errors.count, "error") %> prohibited this quiz from being saved:  </h2>

   <ul>
   <% @quiz.errors.full_messages.each do |msg| %>
     <li><%= msg %></li>
   <% end %>
   </ul>
  </div>
<% end %>

<div class="field">
  <%= f.label :title %><br />
  <%= f.text_field :title %>
</div>
<div class="field">
  <%= f.label :quiz_date %><br />
  <%= f.date_select :quiz_date %>
</div>
<div class="field">
  <%= f.label :reading %><br />
  <%= f.text_field :reading %>
</div>
<div>

  #the problem code
  <% @quiz.questions.each do |questions| %>
  <div class="question">
  <%= f.label :questions %><br />
  <%= f.text_field  %>
  </div>
  <% end %>
  #end problem code

</div>
<div class="actions">
 <%= f.submit %>
</div>
<% 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-06-10T01:48:28+00:00Added an answer on June 10, 2026 at 1:48 am

    You are going to need to adds accepts_nested_attributes in your Quiz model

    Class Quiz < ActiveRecord::Base
     accepts_nested_attributes_for :questions
    

    Then in your form add

       <%= f.fields_for :questions do |build| %>
        <div class="question">
         <%= build.label :questions %><br />
          <%= build.text_field :questions  %> #whatever attribute in your questions model
         <%end%>
    

    You will find this Railscast very helpful, http://railscasts.com/episodes/196-nested-model-form-part-1

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

Sidebar

Related Questions

There are two intents on the receiver side which are called from the same
There is an application written in PHP which I am converting to Ruby. When
There's a Rails 3.2.3 web application which doesn't use any database. But in spite
There is a directed graph having a single designated node called root from which
There are two table s : one is the master and one the detail
There are several shading languages available today like GLSL, HLSL, CG, which one to
There's a bug in FireBug: I accidentally clicked where the line numbers are, which
There's a few previous questions on StackOverflow questioning how one goes about accessing local
There is a div (form) which opens on the click of a button. There
I want use html5's new tag to play a wav file (currently only supported

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.