Skip to content

Instantly share code, notes, and snippets.

View arbarlow's full-sized avatar

Alex Barlow arbarlow

View GitHub Profile
#/usr/bin/ruby
require 'rubygems'
require 'activerecord'
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:host => "localhost",
:username => "root",
:password => "",
:database => "lame"
class ApplicationController < ActionController::Base
before_filter :update_session_expiration_date
private
def update_session_expiration_date
options = ActionController::Base.session_options
unless options[:session_expires]
options[:session_expires] = 1.year.from_now
end

PostgreSQL

Import timing..

Starting Import of Artists… 1335.900000 83.280000 1419.180000 (2532.872472) Finished importing Artists with 518928 new records. 0 old or failed attempts It took approximately -42.2145436333333 minutes

@implementation ResortVenueViewController
@synthesize venue, venueID, managedObjectContext, locationOrPhotos;
- (void)viewDidLoad {
[super viewDidLoad];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity =
[NSEntityDescription entityForName:@"Venue"
development:
access_key_id: XXXXXXXXXXX
secret_access_key: XXXXXXXXXXX
bucket: alexrbarlow-dev
cloudfront_cname: xxxxxxx.cloudfront.net #Optional, without, s3 is used.
has_attached_file :image,
:storage => :s3,
:s3_credentials => "#{Rails.root.to_s}/config/aws.yml",
:path => "images/:id/:style:unix_time.:extension"
class Release < ActiveRecord::Base
has_many :songs
end
# Tell Rails, update a "songs_count" field on the parent record after creation/deletion
class Song < ActiveRecord::Base
belongs_to :release, :counter_cache => true
end
r = Release.first
class Release < ActiveRecord::Base
has_many :songs, :dependent => :destroy
end
# Any song belonging to the Release deleted, will also be deleted
class Order < ActiveRecord::Base
has_many :order_products
validates_associated :order_products # This checks all the order_product instances are valid
end
class OrderProduct < ActiveRecord::Base
belongs_to :order
belongs_to :product
validates :order, :product, :presence => true
end
# This is the wrong was to do this. What if one of the order products fails?
def create
@order = Order.new
if @order.save
for order in params[:order][:product_ids]
OrderProducts.create(:order_id => @order.id, :product_id => Product.find(params[:id]).id)
end
flash[:notice] = "Thanks, your order will be completed shortly!"
redirect_to :action => "index"
else