Invoice and invoice_lines


#1

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


#2

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


#3

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


#4

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.