Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattpolito/70348 to your computer and use it in GitHub Desktop.
Save mattpolito/70348 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment