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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:25:54+00:00 2026-06-08T20:25:54+00:00

Nested form <%= nested_form_for(@bill) do |f| %> <p><%= f.link_to_add Add Product, :bill_line_items %> </p>

  • 0

Nested form

<%= nested_form_for(@bill) do |f| %>

<p><%= f.link_to_add "Add Product", :bill_line_items %> </p>

Partial of bill line items

<%= javascript_include_tag 'bill'%>

<%= f.hidden_field :bill_id %>

<%- prices = Hash[Product.all.map{|p| [p.id, p.price]}].to_json %>

<%= f.label :product_id %>
<%= f.collection_select :product_id ,Product.all,:id,:name, :class => 'product',  :prompt => "Select a Product", input_html: {data: {prices: prices}}%> <br/ >


<%= f.label :price, "price"%> 
<%= f.text_field :price, :size=>20, :class =>"price" %><br/>

bill.js

jQuery(document).ready(function(){
        jQuery('.product').change(function() {
            var product_id = jQuery(this).val();
            var price = eval(jQuery(this).data("prices"))[product_id];
            jQuery('.price').val(price);
        });
    });

Rails 3.2 Issue:
Second click on Add Product & on selecting the product
When we select the second product the price of second product is overwriting on the price of the first selected product.
Request help.

  • 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-08T20:25:56+00:00Added an answer on June 8, 2026 at 8:25 pm

    This is the solution I have arrived at. I believe this is a very bad way to do it But it gets the work done.

    jQuery(document).ready(function(){
      jQuery("customer-outer").delegate("select", "change", function(event){
        var selectElement = jQuery(this);
        var productId = selectElement.val();
        var price = eval(selectElement.data('prices'))[productId];
        var lineItemWrapperElement = selectElement.parent().parent();
        jQuery("input.price", lineItemWrapperElement).val(price);
      });
    });
    

    customer-outer is class of div defined new.html and edit.html. If anyone finds a proper solution for this, please do share.

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

Sidebar

Related Questions

I'm trying to add has_many_through relationship through a form nested in a parent model.
I am trying to build an estimate form that supports multiple line items. After
I have a nested form Parent, which accepts attribute for Child. In my controller#new,
Good day. Has somebody working solution for deleting asset in nested form in Carrierwave?
I have the following form for photo_album which uses the nested forms feature of
I have a nested form in my app that uses AJAX to load an
I have a complicated nested form (Ryan Bates' version) with .live() attached to some
I'm creating a child by my nested form and I know the routes work
I'm having a problem with my nested form. Models: class UserAnswer < ActiveRecord::Base belongs_to
I am running rails 3.2 I have created a nested form (requests > tags)

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.