code
stringlengths
1
1.73M
language
stringclasses
1 value
class CreateActivities < ActiveRecord::Migration def self.up create_table :activities do |t| t.column :activity_type_id, :integer t.column :detail, :string t.column :created_at, :datetime end end def self.down drop_table :activities end end
Ruby
class AddUserCompanyKey < ActiveRecord::Migration def self.up add_column :users, :customer_id, :integer end def self.down remove_column :users, :customer_id end end
Ruby
class ChangeAddressablesToAddresses < ActiveRecord::Migration def self.up drop_table :addressables add_column :addresses, :customer_id, :integer add_column :addresses, :is_default_billing, :boolean add_column :addresses, :is_default_shipping, :boolean end def self.down end end
Ruby
class CreateActivityTypes < ActiveRecord::Migration def self.up create_table :activity_types do |t| t.column :name, :string t.column :icon_name, :string end end def self.down drop_table :activity_types end end
Ruby
class AddOrderCount < ActiveRecord::Migration def self.up add_column :order_statuses, :orders_count, :integer end def self.down remove_column :order_statuses, :orders_count end end
Ruby
class LoadDatabase < ActiveRecord::Migration def self.up create_table "addresses", :force => true do |t| t.column "address", :text t.column "city", :string t.column "postcode", :string t.column "state", :string t.column "country_id", :integer t.column "phone", :string t.colum...
Ruby
class CreatePayments < ActiveRecord::Migration def self.up create_table :payments do |t| t.column :order_id, :integer t.column :amount, :float t.column :method, :integer t.column :created_by_id, :integer t.column :created_at, :datetime t.column :updated_at, :datetime end ...
Ruby
class CreateDiscounts < ActiveRecord::Migration def self.up create_table :discounts do |t| t.column 'rule_name', :string end add_column :pricing, :discount_id, :integer end def self.down drop_table :discounts remove_column :pricing, :discount_id end end
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class Test::Unit::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This ensures that the # test datab...
Ruby
#!/usr/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/usr/local/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.lo...
Ruby
#!/usr/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/usr/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/usr/local/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.lo...
Ruby
#!/usr/local/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai...
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
# This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. ENV["RAILS_ENV"] ||= "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec/rails' Spec::Runner.configure do |config| config.use_transactional_fixtures = true confi...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module CartsHelper end
Ruby
module CartLineItemsHelper end
Ruby
module ProductsHelper end
Ruby
module DashboardHelper end
Ruby
class CartLineItem < ActiveRecord::Base belongs_to :product belongs_to :cart end
Ruby
class ShippingMethod < ActiveRecord::Base end
Ruby
class Payment < ActiveRecord::Base end
Ruby
class SalesAgent < ActiveRecord::Base end
Ruby
class ProductGroup < Product end
Ruby
class OrderStatus < ActiveRecord::Base has_many :orders attr_accessor :next_statuses def self.find_all find(:all, :order => 'sort_order ASC') end def self.next_status(current_status) if current_status.flow_next? find(:all, :conditions => "id IN (#{current_status.flow_next})", :order =...
Ruby
class Agent < Customer #todo rename this to something a lot more meaningful # agent has many customers through ... retailers ? has_many :representations2 , :class_name => 'Representation' has_many :customers, :through => :representations2 end
Ruby
class Product < ActiveRecord::Base has_many :pricings has_many :price_types, :through => :pricings has_many :category_product_links has_many :categories, :through => :category_product_links belongs_to :order_line #used to return the price of the product, pass in PriceType, get out price value #called ...
Ruby
class PriceType < ActiveRecord::Base end
Ruby
class PaymentTerm < ActiveRecord::Base has_many :orders has_many :customers end
Ruby
class Discount < ActiveRecord::Base has_many :pricing has_many :discount_tables, :order => "qty ASC" def get_discount(qty) discount_tables.each do |dt| return dt.discount_applied if qty <= dt.qty end return discount_tables.last.discount_applied end end
Ruby
class Representation < ActiveRecord::Base belongs_to :agent belongs_to :customer end
Ruby
class CustomerStatus < ActiveRecord::Base has_many :customers end
Ruby
class Shipment def get_shipping_amount(opts = {}) #:weight => self.shipping_weight #:dest_city => self.shipping_city #:dest_postal_code => self.shipping_post_code_at_order #:dest_country => self.shipping_country.code return 12.00 end end
Ruby
class OrderPaymentHistory < ActiveRecord::Base belongs_to :order end
Ruby
class Activity < ActiveRecord::Base end
Ruby
class ActivityType < ActiveRecord::Base end
Ruby
class CategoryProductLink < ActiveRecord::Base belongs_to :category belongs_to :product end
Ruby
class Cart < ActiveRecord::Base has_many :line_items, :class_name => 'CartLineItem', :foreign_key => 'cart_id' belongs_to :user def add_product(product, qty = 10) self.line_items.each do |li| if li.product == product li.qty += qty self.save return true end end self.line_items...
Ruby
class OrderStatusHistory < ActiveRecord::Base belongs_to :order belongs_to :order_status end
Ruby
class PaymentMethod < ActiveRecord::Base end
Ruby
class Pricing < ActiveRecord::Base set_table_name 'pricing' belongs_to :product belongs_to :price_type belongs_to :discount def get_unit_price return price end end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base belongs_to :customer has_many :carts # Virtual attribute for the unencrypted password attr_accessor :password validates_presence_of :login, :email validates_presence_of :password, :if => :password_required? validates_presence...
Ruby
class Category < ActiveRecord::Base has_many :category_product_links has_many :products, :through => :category_product_links end
Ruby
class Addressable < ActiveRecord::Base belongs_to :customer belongs_to :address def type self.address_type == 0 ? 'billing' : 'shipping' end end
Ruby
class OrderLine < ActiveRecord::Base belongs_to :order belongs_to :product attr_protected :discount_applied def validate if self.qty_ordered.to_i < 10 errors.add_to_base('You must order more than 10') end end # We need to determine the pricing model for the order (taken from price ...
Ruby
class Customer < ActiveRecord::Base has_many :representations has_many :agents, :through => :representations has_many :orders has_many :addresses has_many :users has_one :default_billing_address, :class_name => 'Address', :foreign_key => 'billing_address_id' has_one :default_shipping_...
Ruby
class Role < ActiveRecord::Base end
Ruby
class Price < ActiveRecord::Base belongs_to :product belongs_to :price_type #used to return the price of the product, pass in PriceType, get out price value #called in OrderLine calculation def self.get_price(price_type) find(:first, :conditions => ['price_type_id = ?', price_type.id] ).price end end...
Ruby
class Address < ActiveRecord::Base belongs_to :country belongs_to :customer validates_presence_of :city, :address def self.default_billing find(:first, :conditions => 'is_default_billing = 1') end def self.default_shipping find(:first, :conditions => 'is_default_shipping = 1') end end
Ruby
class DiscountTable < ActiveRecord::Base end
Ruby
class Country < ActiveRecord::Base has_many :companies end
Ruby
class Order < ActiveRecord::Base DRAFT = 10 PENDING_REVIEW = 12 PAYMENT_SELECTION = 19 PENDING_PAYMENT = 20 #MAYBE THIS CAN BE REMOVED PAYMENT_SENT = 22 PAYMENT_RECEIVED = 24 FINALISED = 25 #NEW STATUS, One of the big three. CREATED FINALISED SHIPPED RECEIVED PAY...
Ruby
class AddressesController < ApplicationController before_filter :find_customer # GET /addresses # GET /addresses.xml def index @addresses = Address.find(:all) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @addresses.to_xml } end end # GET /address...
Ruby
class ProductsController < ApplicationController before_filter :load_category_if_exists before_filter :load_cart # GET /products # GET /products.xml def index if @category @products = category.products.find(:all) else @products = Product.find(:all) end end # GET /products/1 ...
Ruby
class CartsController < ApplicationController # GET /carts # GET /carts.xml def index @carts = Cart.find(:all) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @carts.to_xml } end end # GET /carts/1 # GET /carts/1.xml def show @cart = Cart.find(pa...
Ruby
class CartLineItemsController < ApplicationController # GET /cart_line_items # GET /cart_line_items.xml def index @cart_line_items = CartLineItem.find(:all) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @cart_line_items.to_xml } end end # GET /cart_lin...
Ruby
class AccountController < ApplicationController # Be sure to include AuthenticationSystem in Application Controller instead # include AuthenticatedSystem # If you want "remember me" functionality, add this before_filter to Application Controller #before_filter :login_from_cookie # say something nice, you goof...
Ruby
class CategoriesController < ApplicationController # GET /categories # GET /categories.xml def index @categories = Category.find(:all) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @categories.to_xml } end end # GET /categories/1 # GET /categories/1....
Ruby
class DashboardController < ApplicationController layout 'dashboard' def index end end
Ruby
class UsersController < ApplicationController # render new.rhtml def new end def create @user = User.new(params[:user]) @user.save! self.current_user = @user redirect_back_or_default('/') flash[:notice] = "Thanks for signing up!" rescue ActiveRecord::RecordInvalid render :action => ...
Ruby
# XChain application. # Created by Rowan Hick - rowan@xchain.ca # www.xchain.ca # # Licensed according to Mozilla Public License 1.1 as Follows # # 1. Definitions. # # 1.0.1. "Commercial Use" means distribution or otherwise making # the Covered Code available to a third party. # # 1.1. ''Contributo...
Ruby
# # GET /orders/ # GET /orders/new;select_customer # GET /orders/new {customer id passed in to ?new} # POST /orders # {should be at draft order phase} # To edit an order (customer or agent or manager) # GET /order/id # PUT /order/id # To review an order class OrdersController < ApplicationController #before_filte...
Ruby
# This controller handles the login/logout function of the site. class SessionsController < ApplicationController # Be sure to include AuthenticationSystem in Application Controller instead skip_before_filter :login_from_cookie, :only => [:new, :create] # If you want "remember me" functionality, add this before...
Ruby
class CustomersController < ApplicationController # GET /customers # GET /customers.xml def index @customers = Customer.find(:all, :include => [:country, :status]) respond_to do |format| format.html # index.rhtml format.xml { render :xml => @customers.to_xml } end end # GET /custome...
Ruby
ActionController::Routing::Routes.draw do |map| map.resources :cart_line_items map.resources :carts # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind yo...
Ruby
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb unless defined?(RAILS_ROOT) root_path = File.join(File.dirname(__FILE__), '..') unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end ...
Ruby
# Be sure to restart your web server when you modify this file. # Uncomment below to force Rails into production mode when # you don't control web/app server and can't set it the proper way # ENV['RAILS_ENV'] ||= 'production' # Specifies gem version of Rails to use when vendor/rails is not present #RAILS_GEM_VERSION...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Full error repor...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
module AuthenticatedSystem protected # Returns true or false if the user is logged in. # Preloads @current_user with the user model if they're logged in. def logged_in? current_user != :false end # Accesses the current user from the session. def current_user @current_user ||= ...
Ruby