Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. Invoice.rb:
  2. has_many :service_types, through: :invoice_service_type,
  3.  
  4. Invoice form:
  5. <div class="col-md-12" id="ServiceType">
  6. <strong>Serviços:</strong>
  7. <%= f.simple_fields_for :invoice_service_types do |invoice_service_type| %><br>
  8. <%= render 'invoices/invoice_service_type_fields', f: invoice_service_type %>
  9. <% end %>
  10. </div>
  11. <br/><br/><%= link_to_add_association ' Novo Serviço', f, :invoice_service_types, class: 'fa fa-plus btn btn-success' %>
  12. </div>
  13.  
  14. Invoice Service Types, with fix name of service types, but different values for each Service Type and Invoice.
  15. invoice_service_type_fields form:
  16. <div class="nested-fields form-inline">
  17. <div class="col-xs-12 col-lg-12">
  18. <%= f.association :service_type, collection: ServiceType.all.each.map {|v, k|[v.name, v.id]}, prompt: 'Escolha o Serviço', label: false %>
  19. <%= f.input :value_charged, class: "form-control", placeholder: "Valor cobrado", label: false %>
  20. <%= link_to_remove_association "", f, class:"fa fa-trash-o h3", style:'font-size: 20px;' %>
  21. </div>
  22. </div>
  23.  
  24. InvoiceServiceType.rb
  25. belongs_to :invoice
  26. belongs_to :service_type
  27.  
  28. Schema for InvoiceServiceType: ( this what take me a lot of time, to discover how to have diferent values for same kind os service type )
  29. create_table "invoice_service_types", force: :cascade do |t|
  30. t.float "value_charged"
  31. t.integer "invoice_id"
  32. t.integer "service_type_id"
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement