Displaying 20 results from an estimated 6000 matches similar to: "Adding children via small subform"
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,
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 Jul 30
1
Insert multiple new child records with the parent
Hello,
I am implementing a classic invoice application. On the create new
invoice page
I want to allow users to add new line items using AJAX:
-----------------------------------------------------------------------------
Invoice Date [ ]
Client [ ]
Line Items
1. [ ] $[ ]
<add new line item>
<save> <cancel>
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 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 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
2006 Jan 24
3
Is there a concise way?
Hi,
Is there a concise/ruby way to do the following:
[Note: 1 and 2 below are not related.]
(1)
for p in 0...@order.line_items[k].shipment_lines.length
shipline_qty = shipline_qty +
@order.line_items[k].shipment_lines[p].quantity
end
(2)
ts = Array.new
for tk in s.trackings
ts.push(tk)
end
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 =
2006 Jan 22
2
Is there a way to add items from the bottom of a drop down list
I am writing a banking / accounting / bookkeeping system for myself.
I have orgs (who pay me or who I pay) and line_items (day to day
transactions that mirror the entries on my bank statements)
On my line_items screen I have a select box with various orgs in it.
I''d like to have a way to add an org write there on that screen
rather than have to leave it and go back to the orgs
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 Jan 15
1
Cloning a one-many association
Hi, I want to make a copy of an object with its associations, and I am
looking for an elegant solution. This is what I intuitively think should
work, but it doesn''t:
order2 = order1.clone
order1.line_items.each do |o|
order2.line_items.build(o)
end
This doesn''t work because a model class does not stringify its keys ...
so I can''t pass an object into a method that
2009 Apr 01
3
Nil being coerced to float
I was doing this:
@line_items = LineItems.find_all_by_invoice_id(params[:id])
@payments = Payments.find_all_by_invoice_id(params[:id])
@total = @line_items.sum{ |item| item.cost }
@payment_total = @payments.sum{ |payment| payment.value }
@balance = @total - @payment_total
But when no payments had been made it was coming up with an error when
trying to sum nil, so I did
2006 Jan 12
5
Question about using DISTINCT in ActiveRecord find method.
Hi,
Am relatively new to the RoR world. My question is quite simple.
I have a query like such:
shipmentNumbers = Order.find_by_sql(["select distinct s.id from orders
o, line_items li, shipment_lines sl, shipments s where o.number=? and
o.id = li.order_id and li.id = sl.line_item_id and sl.shipment_id =
s.id", number])
The above query works fine. I wanted to do the same query using
2011 Aug 02
1
NoMethodError in Store#index
Thanks in advance
I want to know how to solve No method errors
Agile Rails 4th ed
Great book
But second time I get this type of error
I would like to know how to troubleshoot and resolve
Please see below thanks once again
NoMethodError in Store#index
Showing C:/rails/shop9/app/views/line_items/_line_item.html.erb where
line #9 raised:
undefined method `title'' for nil:NilClass
2006 Feb 05
8
Agile Rails book: depot problem
I recently finished the first part of the "Agile Rails" book. But, the
depot doesn''t completely work as it should. I still have 2 problems:
I will explain them in 2 threads.
The first one is:
I can''t destroy products (I can only creat and update them). When I try
to delete a product --> http://localhost:3001/admin/destroy/3
I get this error message:
2007 May 05
3
DB trigger vs before_create
Hello everyone,
I''m having trouble figuring out which approach is better.
I have the following tables: products, orders and line_items.
Every time an Order is placed, the quantity field in the products
table has to be updated for each LineItem in the Order. One option is
to use DB triggers which is not as portable as using before_create in
the Order model. But with before_create I cannot
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