On 15 February 2011 12:29, Lorenzo Brito M.
[email protected] wrote:
give us the controller and the view
class DeliveriesController < ApplicationController
respond_to :html
debugger
def create
@customer = Customer.find(params[:customer_id])
@delivery = @customer.deliveries.build(params[:delivery])
@document = @customer.build_document(params[:document])
if @delivery.valid? and @document.valid?
Delivery.transaction do
@delivery.save!
@document.save!
end
flash[:success] = “Consegna effettuata.”
respond_with(@customer)
else
@products = Product.all
render ‘customers/show’, :layout => ‘delivery’
end
end
end
<%= simple_form_for([@customer, @customer.deliveries.build]) do |f| %>
<%= render ‘shared/error_messages’, :object => @delivery %>
<%= f.input :delivered_at, :as => :hidden, :input_html => { :value
=> Date.today } %>
Seleziona tutti
|
Annulla
<% for product in @products %>
<%= check_box_tag 'delivery[product_ids][]', product.id,
(@delivery.products.include?(product) if @delivery) %>
<%= product.description %>
<% end %>
<%= f.error :delivery_products %>
<%= simple_fields_for @customer.build_document do |doc| %>
<%= render 'shared/error_messages', :object => @document %>
<%= doc.label :doc_type %>:
<%= doc.text_field :doc_type, :value =>
(params[:document][:doc_type] if @document) %>
<%= doc.label :doc_number %>:
<%= doc.text_field :doc_number, :value =>
(params[:document][:doc_number] if @document) %>
<%= doc.label :issued_by %>:
<%= doc.text_field :issued_by, :value =>
(params[:document][:issued_by] if @document) %>
<% end %>
<%= f.submit 'consegna' %>
<% end %>