Skip to content

Instantly share code, notes, and snippets.

# In my Image Bank Rails App
class Payment < ActiveRecord::Base
default_scope :conditions => { :application => 'ImageBank' }
before_save { |p| p.application="ImageBank" }
end
# In my Live Performances Rails App
class Payment < ActiveRecord::Base
default_scope :conditions => { :application => 'LivePerformances' }
before_save { |p| p.application="LivePerformances" }
#contenth
%ol#steps_menu
- tabs_for :step => active_step do |t|
= t.link_to "1. start", :step=> "1start"
= t.link_to "2. price", :step=> "2price"
= t.link_to "3. bill", :step=> "3bill"
= t.link_to "4. payment", :step=> "4payment"
= t.link_to "5. end", :step=> "5end"
=render :partial => "/admin/orders/steps/step_#{active_step}"
module TabsHelper
# takes the block
def tabs_for(current_tab, &block)
yield Tab.new(current_tab, self)
end
class Tab
def initialize(current_tab, template)
@current_tab = current_tab
module OrdersHelper
# helper to determine the active order step given :
# 1. a params[:step]
# 2. if none, according to the order's state
def active_step
@active_step ||= if params[:step]
params[:step]
elsif %(opened).include? @order.state
"1start"
class PseudoAR
def self.find(args)
new.tap do |ar|
# do some crazy SQL
end
end
def self.create(args)
new.tap do |ar|
# do some crazy validation
module RAAWS
ONE_NECESSARY_SEARCH_PARAM =%w<
Actor Artist AudienceRating Author
Brand BrowseNode Composer Conductor CityDirector
Keywords Manufacturer MusicLabel Neighborhood
Orchestra Power Publisher TextStream Title>
class ItemOperation < Operation
def self.lookup(item_id, index=nil, &block)
new.tap do |obj|
class PaymentsController < ApplicationController
before_filter :find_payment
layout "secure"
def show(); end
private
def find_payment
@payment = current_order.payment
end
#route.rb
map.resources "orders", order_hash do |order|
order.resource "invoice"
order.resource "payment", :new => {"express" => :get}
end
#map.resoures "payments" # not in use anymore !
#payments_controller.rb
before_filter :require_order
def show
module Creme
def cost
super + 0.4
end
end
class Coffee
def cost
3
end
require 'rubygems'
require 'mixology'
module Creme
def cost
super + 0.4
end
end
class Coffee