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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T03:47:46+00:00 2026-06-08T03:47:46+00:00

I have a nested form that has a select dropdown menu. How can I

  • 0

I have a nested form that has a select dropdown menu.

How can I pass the selected item’s ID into the attributes that are submitted when the ‘submit’ button is hit?

In my situation, this is what my nested form’s partial looks like:

=select("dish", "menu_id", Menu.all.collect {|r| [ r.name, r.id ] }, {:include_blank => 'Choose a Menu'})  
=f.hidden_field :_destroy
=f.text_field :name, placeholder: "Name"
=f.text_field :price, placeholder: "Price"
=link_to "X", '#', :class => "remove_fields"

When I hit the submit button, the Terminal/Console displays that the following are being submitted to the database but you’ll notice that the menu_id from the dropdown menu isn’t part of the dishes_attributes since it doesn’t share the same input id and name as the other two fields.

... "dishes_attributes"=>{"1342759486320"=>{"_destroy"=>"false", "name"=>"Dish 1", "price"=>"32"} ...

From the HTML source code, the name and price input fields get assigned the following id and name:

<input id="side_dish_dishes_attributes_1342759902918_name" name="side_dish[dishes_attributes][1342759902918][name]" placeholder="Name" size="30" type="text"/>
<input id="side_dish_dishes_attributes_1342759902918_price" name="side_dish[dishes_attributes][1342759902918][price]" placeholder="Price" size="30" type="text"/>

But my select dropdown looks like this:

<select id="dish_menu_id" name="dish[menu_id]">
  <option value="">Choose a Menu</option>
  <option value="1">Menu 1</option>
  <option value="2">Menu 2</option>
</select>

In the parent _form page, here’s what the call looks like that then calls this partial:

=link_to_add_fields "Add New Dish", f, :dishes

With the link_to_add_fields looking like this from my helpers/application_helper.rb:

def link_to_add_fields(name, f, association)
  new_object = f.object.send(association).klass.new
  id = new_object.object_id
  fields = f.fields_for(association, new_object, child_index: id) do |builder|
    render(association.to_s.singularize + "_fields", f: builder)
  end
  link_to(name, '#', class: "add_fields", data: {id: id, fields: fields.gsub("\n", "")})
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-08T03:47:49+00:00Added an answer on June 8, 2026 at 3:47 am

    Instead of this line

    =select("dish", "menu_id", Menu.all.collect {|r| [ r.name, r.id ] }, {:include_blank => 'Choose a Menu'})  
    

    use it with form object

    =f.select("menu_id", Menu.all.collect {|r| [ r.name, r.id ] }, {:include_blank => 'Choose a Menu'})
    

    I hope this will sort out your id problem as well as part of dishes attributes

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

Sidebar

Related Questions

I have a sign-up form that has nested associations/attributes whatever you want to call
I have a Ruby on Rails app that has a form with nested attributes.
I have a nested form in my app that uses AJAX to load an
I have a form that people can use to send emails to our clients.
I have a form for a nested resource (Client :has_many Workouts) that I want
I have an invoice model, that has many invoice items. I have a form
I got a form that have a nested link. The problem that the link
I have a nested structure that can't be edited because of some hosted jQuery,
How can I generate form fields for a has_many :through association that has additional
I have a Page (form) that has many UserControls on it, and I'm trying

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.