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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:11:25+00:00 2026-05-17T16:11:25+00:00

I have a form for creating/editing an event. There is a Client drop down

  • 0

I have a form for creating/editing an event. There is a Client drop down which renders some custom questions and answers dependent on the selected Client.

I’m running Rails 2.3.9 with Ruby 1.8.6 and Mongrel on Windows.
Here is the relevant code:

Event form

- form_for @event do |f|
    ....
    = f.collection_select(:client_id, Client.all, :id, :name)

    #custom_client_fields
      = render 'client_fields' if @client

    = observe_field :event_client_id, :url => {:action => 'client_fields'}, 
                    :with => "'client_id=' + encodeURIComponent(value)"
    ....

_client_fields.html.haml

- fields_for "event[client_attributes]", @client do |client|
  - client.fields_for :questions do |question|
    %label.question= question.object.content
    - question.fields_for :answers, Answer.new do |answer|
      = answer.text_field:content, :maxlength => 150, :size => 40

Event Controller

def client_fields
  if params[:client_id].blank?
    render_no_client_fields #self explanatory
  else
    respond_to do |format|
      format.js {
        render :update do |page|
          page[:custom_client_fields].replace_html :partial => 'client_fields', :layout => false
        end
      }
    end
  end
end

Parameter hash

Parameters: {
  "event"=>{
    "id"=>"2",
    "client_attributes"=>{
      "questions_attributes"=>{
        "0"=>{
          "id"=>"4",
          "answers_attributes"=>{
            "0"=>{
              "content"=>"fjhkghjkk"
            }
          } 
        }
      }
    }
  }
}

Basically the form passes the validations and everything except the nested attributes. Nothing is inserted into the database table.

Looking at the parameter hash my client_attributes doesn’t have an id… hmmm…

  • 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-17T16:11:26+00:00Added an answer on May 17, 2026 at 4:11 pm

    In the client_fields partial I had to add the following code to set the client_attributes_id:

    <input id="event_client_attributes_id" name="event[client_attributes][id]" type="hidden" value="#{@client.id}">
    

    Note to self: When you don’t use Rails’ magic form helpers you have to build the rest of the form as well.

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

Sidebar

Related Questions

I have subclassed Form to include some extra functionality, which boils down to a
I have a problem creating some form of hierarchy with different object types. I
I have a Rails form that is being used for creating and editing a
I have a form with some radio buttons that are disabled by default. When
I have a form in which people will be entering dollar values. Possible inputs:
I have a form that contains a GridView control which is databound to an
I have a form and am creating controls, adding them at runtime. How do
I have a form with a panel on which I dynamically load multiple user
I am creating a form, using Zend Form. I have 8 input elements. And
I have a login.jsp page which contains a login form. Once logged in the

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.