Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
def remove_existing_customers!(customer_attribs, tour_id = nil) existing_customers = [] customer_attribs.reject! do |key, value| existing_customer = nil tour = Tour.find(tour_id) if tour_id if value['id'].nil? || (tour && tour.customers.detect { |customer| customer.id.to_s == value['id'].to_s }.nil?) if existing_customer = Customer.find_by_name(value['name']) existing_customers << existing_customer end end existing_customer end unless customer_attribs.nil? existing_customers end # POST /tours # POST /tours.xml def create existing_customers = remove_existing_customers!(params[:tour][:customers_attributes]) @tour = Tour.new(params[:tour]) respond_to do |format| if @tour.save @tour.customers << existing_customers @tour.save flash[:notice] = 'Tour was successfully created.' format.html { redirect_to(@tour) } format.xml { render :xml => @tour, :status => :created, :location => @tour } else format.html { render :action => "new" } format.xml { render :xml => @tour.errors, :status => :unprocessable_entity } end end end
This paste will be private.
From the Design Piracy series on my blog: