mattpolito (owner)

Revisions

gist: 70348 Download_button fork
public
Public Clone URL: git://gist.github.com/70348.git
Embed All Files: show embed
Rails 2.3 nested object form - WHAT AM I DOING WRONG?! #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
When new line link is pressed, I get a new line to appear in my table... but the attributes for the new line are always the same as the first (invoice[line_attributes][new_1])
 
What am I missing?
 
## app/views/invoices/new.html.haml
- form_for @invoice do |invoice_form|
  = invoice_form.error_messages
  = render :partial => 'invoice', :object => invoice_form
  .field
    = invoice_form.submit 'Save Invoice'
 
## app/views/invoices/_invoice.html.haml
%tbody#invoice_line_item_rows
  - invoice.fields_for :lines do |line_fields|
    = render :partial => 'line', :object => line_fields
  = add_line_item_link('Add new line', @client)
 
## app/views/invoices/_line.html.haml
%tr
  %td.item.delete.first
  %td.item.kind= line.collection_select :line_type_id, LineType.all, :id, :name
  %td.item.quantity= line.text_field :quantity, :size => 4, :class => "text limited"
  %td.item.description= line.text_area :description
  %td.item.tax= line.check_box :has_tax
  %td.item.price= line.text_field :unit_price, :size => 8, :class => "text limited"
  %td.item.total.last
 
## app/helpers/invoices_helper.rb
def add_line_item_link(name, invoice)
  link_to_function name do |page|
    page.insert_html :bottom, :invoice_line_item_rows, :partial => 'line', :object => invoice.lines.build
  end
end