I’m creating a billing application in rails3, I have a confusion when it comes to creating a bill.
one bill can have one or more items
'bill' has many 'items'
'item' belongs to 'bill'
my requirement is as follows
I should be able to create a new bill and add items to it (any number of items can be added)
my problem is
1 – to get items to be saved in the bill_details table I should first generate bill_id, What is the best way to generate this bill id.
2 – what is the best way to implement a scenario like this
3 – can i get any help from rails nested forms
thanks
cheers
sameera
You should use polymorphic association in this scenario. Here what you can do to achieve this:
in bill.rb # model file:
in item.rb # model file :
In your bills_controller.rb create normal actions :
index, new, create, show, edit, update, deletefor update action:
and you don’t have to bother to create any action/ method in your items_controller.rb, just create a partial _form.html.erb in view/Items/_form.html.erb and put this:
Now you have to call this from your view/bills/_form.html.erb:
View/Bills/new.html.erb:
View/Bills/edit.html.erb:
Regards,
Surya