# Invoice and invoice\_lines

**URL:** <https://www.ruby-forum.com/t/invoice-and-invoice-lines/62578>\
**Category:** Rails\
**Created:** [June 6, 2006, 8:35am UTC](https://www.ruby-forum.com/t/invoice-and-invoice-lines/62578 "2006-06-06T08:35:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [June 6, 2006, 8:35am UTC](https://www.ruby-forum.com/t/invoice-and-invoice-lines/62578/1 "2006-06-06T08:35:20Z")

</div>

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  
the user to enter all of the order details, etc. Then, the user will  
want to add invoice\_lines, which are obviously associated with the  
order.

The easiest solution I can think of is to have a session variable  
(session[:invoice\_id]?) so that the application “remembers” which  
invoice you are dealing with (and in fact can also show the heading for  
it etc.).  
I can see problems here though, in case for example I want to allow the  
user to add order\_lines from the same page as the invoice\_view using  
Ajax. The scenario is clear: the user opens an order. Then he opens  
another order and adds some order\_lines there. Then… well, he goes  
back to the first window, and - surprise surprise - he will be adding  
line\_items to the wrong invoice!

The super-easy solution then is to simply have the invoice\_id as a  
parameter of the action that deals with adding line\_items. That way Ajax  
is happy, I am happy… but would this really be the right way to do  
things?

Well, apologies if this question is lame. I just want to make sure…

Bye,

Merc.

[http://www.freesoftwaremagazine.com](http://www.freesoftwaremagazine.com)

---

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [June 6, 2006, 12:16pm UTC](https://www.ruby-forum.com/t/invoice-and-invoice-lines/62578/2 "2006-06-06T12:16:02Z")

</div>

Hello,

Any takers on this one?

(I sent this message as “guest”. I wonder if people actually received  
it…)

Merc.

Tony M. wrote:

> 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  
> the user to enter all of the order details, etc. Then, the user will  
> want to add invoice\_lines, which are obviously associated with the  
> order.
> 
> The easiest solution I can think of is to have a session variable  
> (session[:invoice\_id]?) so that the application “remembers” which  
> invoice you are dealing with (and in fact can also show the heading for  
> it etc.).  
> I can see problems here though, in case for example I want to allow the  
> user to add order\_lines from the same page as the invoice\_view using  
> Ajax. The scenario is clear: the user opens an order. Then he opens  
> another order and adds some order\_lines there. Then… well, he goes  
> back to the first window, and - surprise surprise - he will be adding  
> line\_items to the wrong invoice!
> 
> The super-easy solution then is to simply have the invoice\_id as a  
> parameter of the action that deals with adding line\_items. That way Ajax  
> is happy, I am happy… but would this really be the right way to do  
> things?
> 
> Well, apologies if this question is lame. I just want to make sure…
> 
> Bye,
> 
> Merc.
> 
> [http://www.freesoftwaremagazine.com](http://www.freesoftwaremagazine.com)

---

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [June 6, 2006, 1:50pm UTC](https://www.ruby-forum.com/t/invoice-and-invoice-lines/62578/3 "2006-06-06T13:50:05Z")

</div>

why not do it all in one form (invoice and line item creation), thereby  
removing the need to track an invoice id at all?

---

<div class="post-metadata">

**Author:** ![merc](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@merc](https://www.ruby-forum.com/u/merc)\
**Post date:** [June 6, 2006, 3:03pm UTC](https://www.ruby-forum.com/t/invoice-and-invoice-lines/62578/4 "2006-06-06T15:03:50Z")

</div>

Chris H. wrote:

> why not do it all in one form (invoice and line item creation), thereby  
> removing the need to track an invoice id at all?

How would you do that?  
(In general terms/guidelines…)

Bye!

Merc.
