Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
## orders_controller.rb (snippet) def new @user = current_user @order = Order.new(:user_id => @user.id, :order_status => "initial", :checkout_at => Time.now, :apples => ???) @order.save end ### order.rb class Order < ActiveRecord::Base attr_accessor :apples has_and_belongs_to_many :line_items belongs_to :user validates_numericality_of :user_id after_create :create_line_items def create_line_items apples.each do |a| item = LineItem.new(:inventory_id => a.id, :price_plan_id => a.price_plan_id, :qty => a.quantity, :customer_price => a.price) self.line_items << item end end def total_price LineItem.sum(:customer_price, :conditions => ["order_id = ?", self]) end en
This paste will be private.
From the Design Piracy series on my blog: