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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:36:37+00:00 2026-05-20T04:36:37+00:00

I have been following the railscasts ‘Nested Model Form Parts 1 & 2’ about

  • 0

I have been following the railscasts ‘Nested Model Form Parts 1 & 2’ about the survey form containing questions which in turn contain answers.
The thing is that when the survey form is initially displayed, a question field, along with one answer field are displayed.
When user clicks on the ‘Add Question’ field, only the question field is displayed. No answer field is displayed until user clicks on ‘Add Answer’.

I would like both a question field and an answer field to be initially displayed when user clicks on ‘Add Question’.

Currently the code is like this:

# helpers/application_helper.rb
module ApplicationHelper

  def link_to_add_fields(name, f, association)
    new_object = f.object.class.reflect_on_association(association).klass.new
    fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
      render(association.to_s.singularize + "_fields", :f => builder)
    end
    link_to_function(name, h("add_fields(this, \"#{association}\", \"#{escape_javascript(fields)}\")"))
  end
end




// application.js

function add_fields(link, association, content) {
  var new_id = new Date().getTime();
  var regexp = new RegExp("new_" + association, "g")
  $(link).up().insert({
    before: content.replace(regexp, new_id)
  });
}

Any help will be much appreciated.

Thanks a lot 🙂

  • 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-20T04:36:38+00:00Added an answer on May 20, 2026 at 4:36 am

    The render(association.to_s.singularize + "_fields", :f => builder) calls a partial that contains the question field . You should look for the _question_fields in view/questions/ directory and add an answer field there

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

Sidebar

Related Questions

ok, I've been following: http://railscasts.com/episodes/196-nested-model-form-part-1 Here are the steps I've had to accomplish so
I have been following the ExtDirectSpring form posting guide closely. I defined an api
I have been following a good tutorial about creating a Button skin that allows
I have been following this convention thus far: std::string line; while(std::getline(in,line)) { if(line.size() &&
I have been following the Railscast #270 found Rails Cast #270 about implementing Authentication
I've been following RailsCast 197 to try this nested models/forms and have cracked my
I have been following the usage of JavaScript for the past few years, and
I have been following the following post on using multiple ItemTemplates in a ListView
I have been following mozilla developer network's docs and created a transition for my
I have been following a couple of articles regarding RESTful web services with WCF

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.