similar to: Insert multiple new child records with the parent

Displaying 20 results from an estimated 7000 matches similar to: "Insert multiple new child records with the parent"

2006 Jun 06
3
Invoice and invoice_lines
Hello People, I have a possibly very lame question. I am fairly new to RoR, and I want to make sure I do it "right". I have a model called Invoice, and one called InvoiceLines. Usual story: the table "invoice" has a 1:n relationship with "invoice_lines", which includes invoice_id. Now... the application will have a "new order" button, which will allow
2006 May 02
4
Bug in rails ?
Hi ! I just have a simple question. I am writing an app using rails to familiarize myself with the framework (which is pretty cool, by the way). I just wanted to know why these two work differently (since "find" should be a synonym for "detect" according to the Pick Axe) : current_item = @invoice.line_items.detect {|i| i.product.id == key} current_item =
2012 Sep 01
4
Basic Paypal
Hi all i am following this like for basic paypal http://railscasts.com/episodes/141-paypal-basics and i got this error View: <%= link_to "Checkout", @cart.paypal_url() %> undefined method `paypal_url'' for nil:NilClass despite i have this code in my model called Card Cart Model: class Cart < ActiveRecord::Base def paypal_url(return_url) values = {
2006 Jun 02
0
Problem updating child row from parent model
I developped a web site with Ruby on Rails, but I get a problem during the testing. I have a parent table called "orders" and a child table called "line_items". I created some data for the test in the files "test/fixtures/orders.yml" and "test/fixtures/line_items.yml". In the file "test/unit/order_test.rb" I wrote some code to test the
2006 Jul 21
1
How to dynamically add more rows and submit data
Let''s assume that I am trying to build an application where the user can enter invoice. In the app the user can add lines items. Each line item has decription, date, rate and hours. When the invoice screen comes up the first time I have one blank row for the line items. <tr> <th>Description</th> <th>Date</th>
2005 Oct 14
0
Adding extra field in form using ajax causes extra field to be overwritten, any way around that.
I''m having trouble when I try to add another field in the form using ajax. I''m trying to add another line_item object into the invoice and i''m using the link_to_remote function to implement this. When I do that though and submit to the form, the line_item entries all have the same field name so they get overwritten. I''m not sure how to get around that. Here is
2006 Mar 20
1
Running total of a field in child records
What is the best way to get the running total of a number field in child records. Let say I have an Order model, which has_many :line_items, and each LineItem has an amount field. I would like to get the grand total of a specific Order. Is it a good idea to add a ''total'' column in the ''orders'' table and update it every time a line_item is
2008 Apr 23
1
Validation dependent on unsaved parent
I''m having trouble with a validation that depends on an attribute of a belongs_to parent. If the child is added to an unsaved parent (parent.children << new child), the has_many collection parent.children includes the unsaved child. However the belongs_to attribute child.parent appears to be nil until the parent has been saved. Without access to the parent attributes, the validation
2006 Dec 07
2
Problem saving parent and children using belongs_to, class_name, and foreign_key
Hi, I have a real simple association setup here that''s just trying to: - Create a new PayjunctionOrder - Create some LineItem objects and assign them to the PayjunctionOrder - Save everything I''m using Rails Edge. ---- class PayjunctionOrder < ActiveRecord::Base has_many :line_items end ------------------ ---- class LineItem < ActiveRecord::Base belongs_to :order,
2005 Dec 15
12
Adding multiple invoice items to an invoice on the same form
Hi Friends , Got a unique requirement .I am designing a invoice printing system .So right now I have the NEW page for adding the invoice details to the table .Now I have the requirement of adding Invoice Items In the same form .I have added multiple text boxes to enter the values of the Items using <%= text_field ''invoiceitems[]'', ''item_price''
2008 Feb 20
1
text_field_tag - different parameter name
Hi, I have one problem with validation I am creating e-shop and I have products. This view look like this: <% for product in @category.products %> <div class="produktyBox"> <%= product.title %><br /> Price: <br /> <div style="color:red; font-size:large; font-weight:bold; margin- bottom:5px"><%=
2010 Apr 13
5
How to check if a parent has children?
What is the new way to check if a parent has child items? In rails 1.2.6 I did this: if @client.has_line_items? Client being the parent and line_items the children. Now that I have upgraded to rails 2.0.1 (on my way to current :-) ) I am getting this message: undefined method `has_line_items?'' for #<Client:0x7f3b093b01a0> How should I format the query now? Regards, Paul
2007 Nov 20
3
How to test views with Nested Resources and Partials
Hi everyone, I am relatively new to rspec and I am running into a wall in testing my views. I have a RESTful resource Contracts with a nested resource of Line_items. I am trying to figure out how to test the "edit" form of the Line_items. What complicates this is the nested routing and how to account for it, and that there is a partial form (_form.haml) that both the edit.haml and
2006 Jan 15
6
Saving one-many associations (elegant solution please)
What is the most elegant way to save new one-many associations? order = Order.new(:name => "My Order") order.line_items << LineItem.new(:product_id => 1, :quantity => 2) order.line_items << LineItem.new(:product_id => 2, :quantity => 5) order.save The above - which is by far the most elegant way of putting it - doesn''t work for me - the line_items
2006 Sep 03
2
Undefined method "xxx" of a model when calling a helper
Hi all I''m creating a shop page. I have a cart model that looks like the following: class Cart attr_reader :line_items def get_line_item id @line_items.each do |l| return l if l.id == id end end def initialize @line_items = [] end def empty! initialize end def empty? return true if @line_items.empty? false end end And I have some
2006 Jul 01
3
best approach to add form elements dynamically
I am struggling with how to add dynamically add form elements to a form based on user action. Now here is my situation: I have model Project that has_many line_items On the form to create a project I initially display form elements (some drop downs and text boxes) for adding just one line_item. There is also a button or a link on the page (not sure if this should be in the main form or
2006 Jul 20
1
Having issues saving line items to the DB
Hello everyone, I''m fairly new to Rails (writing my first real app) and brand new to this mailing list. I''ve got a rails/sql error I just can''t seem to solve. It''s probably really simple, but I''m been googling and reading for a day and have made zero progress on it. Hopefully someone on this list can shine some light on my problem, or point me in the
2006 Jun 24
2
Migrations problem with Agile Rails book
I am following the instructions on Agile Web Development with Rails book "Iteratio E1: Capturing an Order" section. When I run the migrations I get the following error. rake db:migrate (in /Users/balaparanj/work/depot) -- execute("alter table line_items \n add constraint fk_line_item_products \n foreign key (product_id) references products(id)") rake
2006 Feb 04
1
Error when using form helper and child objects
Hi, This is one problem that has gotten me stumped for quite a while. I have an Item that has_many :DeliveryMethod, and what I seek to achieve is to create a form that''d let me create an Item, as well as its DeliveryMethods in 1 single form. And so I tried something like: <%= text_field_tag ''Item[DeliveryMethod][price]'', @Item.DeliveryMethod ?
2006 Oct 13
3
How to get a count of line_items
I am fairly new to Rails, and I am having difficulty in forgetting the old way of developing and using the Rails way. This is my question, using orders and line_items as an example. An order has_many line_items A line_item belongs to order In my OrdersController I have def summary @orders = Orders.find(:all) render :xml => @orders.to_xml() end What I want to achieve is to