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

  • Home
  • SEARCH
  • 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 8478167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:40:18+00:00 2026-06-10T18:40:18+00:00

I am watching on railscasts and tried to write the example with my own

  • 0

I am watching on railscasts and tried to write the example with my own hands.
But I got an trouble with the step of: Creating The Form.

It requires creating association between Survey and Question.
But this association cannot be established in my rails application so no questions appear in the form

Here are the codes

Survey model:

class Survey < ActiveRecord::Base
  attr_accessible :name, :questions
  has_many :questions, :dependent => :destroy
  accepts_nested_attributes_for :questions

end

Question model:

class Question < ActiveRecord::Base
  attr_accessible :context, :survey_id
  belongs_to :survey
end

Surveys_Controller method:

  # GET /surveys/new
  # GET /surveys/new.json
  def new
    @survey = Survey.new
    3.times {@survey.questions.build}


    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @survey }
    end
  end

question part in _form.html.erb

  <% f.fields_for :questions do |builder|%>
    <%= builder.label :context, "Question" %><br />
    <%= builder.text_area :context, :rows => 3 %>
  <% end %>

Here is what I got from testing in console

irb(main):010:0> @survey = Survey.new
=> #<Survey id: nil, name: nil, created_at: nil, updated_at: nil>
irb(main):011:0> 3.times {@survey.questions.build}
=> 3
irb(main):012:0> @survey.questions
=> [#<Question id: nil, survey_id: nil, context: nil, created_at: nil, updated_a
t: nil>, #<Question id: nil, survey_id: nil, context: nil, created_at: nil, upda
ted_at: nil>, #<Question id: nil, survey_id: nil, context: nil, created_at: nil,
 updated_at: nil>]
  • 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-10T18:40:20+00:00Added an answer on June 10, 2026 at 6:40 pm

    haha, i am being stupid.
    It is a dumb question.
    It doesn’t matter about the association.

    I made a typing mistake on

    <% f.fields_for :questions do |builder|%>

    it should return some texts inserting into HTML document rather than just processing as ruby code

    it should be <%= f.fields_for :questions do |builder|%>

    But thank you all of your answers 🙂

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

Sidebar

Related Questions

I'm watching a RailsCast on polymorphic associations. http://railscasts.com/episodes/154-polymorphic-association?view=asciicast There's three different models Article, Photo
Watching a WWDC 2011, I saw advice (but not an explanation) that one should
After watching RailsCasts #273 I want to use the Geocoder gem. I've seen this:
I've just finished watching both Railscasts' episodes on Elasticsearch . I've also went ahead
I have been watching Ryan Bates' RailsCasts for years now, and I'm also a
I was watching http://railscasts.com/episodes/362-exporting-csv-and-excel?view=asciicast about exporting tables and follow all steps. I have in
When watching a video on youtube you get a dark player But when you
I have been watching a tutorial for a game in blender, but when I
After watching, the latest RailsCasts with the include and joins information, I know I
newbie alert I'm watching one of Ryan Bate's RailsCasts on virtual attributes. He's adding

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.