Forum: Ruby on Rails Invoice and invoice_lines

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D521c0db52fe0b14d799dd669d536098?d=identicon&s=25 Tony Mobily (Guest)
on 2006-06-06 08:35
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
D521c0db52fe0b14d799dd669d536098?d=identicon&s=25 Tony Mobily (merc)
on 2006-06-06 12:16
Hello,

Any takers on this one?

(I sent this message as "guest". I wonder if people actually received
it...)

Merc.

Tony Mobily 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
A2c85dc5ee81b12e3cc0a6522e8d079d?d=identicon&s=25 Chris Hall (Guest)
on 2006-06-06 13:50
(Received via mailing list)
why not do it all in one form (invoice and line item creation), thereby
removing the need to track an invoice id at all?
D521c0db52fe0b14d799dd669d536098?d=identicon&s=25 Tony Mobily (merc)
on 2006-06-06 15:03
Chris Hall 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.
This topic is locked and can not be replied to.