My Recent Pastes (14 and counting)
Pastes by Ben Curtis (14 and counting)
Below are the 14 most recent pasties by Ben Curtis.
October 03, 2007
6:33PM EDT
by Ben Curtis
View more (124 lines)
require 'net/http' require 'net/https' require 'hpricot' require 'ostruct'
September 05, 2007
10:57AM EDT
by Ben Curtis
View more (9 lines)
def truncate_on(text, length = 30, truncate_string = '...', separator = nil)
return text unless text.respond_to?(:split) && text.length > 0
if separator
new_text = text.split(separator)[0...length].join(separator)
new_text == text ? new_text : new_text + truncate_string
July 09, 2007
1:32PM EDT
by Ben Curtis
<%= text_field 'new_variant[]', 'distributor', :index => @new_variant.variant.id, :autocomplete => 'off', :size => 20 %>
May 18, 2007
5:03PM EDT
by Ben Curtis
View more (8 lines)
railsconf:~$ rake spec Rabble's presentation - should not suck
August 15, 2006
5:04PM EDT
by Ben Curtis
View more (6 lines)
def assert_difference(object, method = nil, difference = 1, reload = false)
initial_value = object.send(method)
yield
object.reload if reload
assert_equal initial_value + difference, object.send(method), "#{object}##{method}"
August 15, 2006
4:58PM EDT
by Ben Curtis
View more (12 lines)
def test_change_quantity_for_product
@cart = carts(:first)
@item = @cart.line_items[0]
assert_no_difference @cart.line_items, :count do
assert_difference @item, :quantity, 1, true do
June 20, 2006
4:40PM EDT
by Ben Curtis
View more (9 lines)
class PaymentMethod < ActiveRecord::Base
def authorize(amount)
processor = Payment::TrustCommerce.new('billingid' => self.processor_id)
if !processor.process('preauth', 'amount' => amount.to_s)
raise PaymentMethodError, processor.error
June 20, 2006
4:34PM EDT
by Ben Curtis
View more (12 lines)
class Sale < ActiveRecord::Base
def validate_on_create
...
amount_to_auth = self.total_price - self.voucher_total
June 20, 2006
6:40AM EDT
by Ben Curtis
View more (11 lines)
class Album < Product
belongs_to :artist
has_many :tracks, :order => 'position', :dependent => true,
:foreign_key => 'product_id'
June 20, 2006
6:38AM EDT
by Ben Curtis
View more (11 lines)
class Album < Product
belongs_to :artist
has_many :tracks, :order => 'position', :dependent => true,
:foreign_key => 'product_id'
June 20, 2006
6:35AM EDT
by Ben Curtis
View more (10 lines)
class Shipment < ActiveRecord::Base
after_create :credit_affiliate
def credit_affiliate
if self.affiliate
June 20, 2006
6:32AM EDT
by Ben Curtis
View more (10 lines)
class CartController < ApplicationController
def checkout
...
@sale = Sale.new(:account => @session[:user],
:payment_method => @session[:payment],
June 20, 2006
6:27AM EDT
by Ben Curtis
View more (7 lines)
class ApplicationController < ActionController::Base
def affiliate_check
if affiliate = params[:affiliate]
cookies[:affiliate] = { :value => affiliate, :expires => 1.week.from_now }
end
June 20, 2006
6:23AM EDT
by Ben Curtis
View more (6 lines)
<div id="plugin">
<h3>Latest Plugin</h3>
<dl id="plugins">
<%= render :partial => 'plugins/plugin', :locals => { :plugin => @plugin } %>
</dl>
