Skip to content

Instantly share code, notes, and snippets.

View pdswan's full-sized avatar

Peter Swan pdswan

View GitHub Profile
@pdswan
pdswan / gist:2475472
Created April 24, 2012 01:51
Console for Sinatra
irb -r path_to_app.rb
@pdswan
pdswan / gist:2475468
Created April 24, 2012 01:50
Deploy branch to heroku
git push heroku branch_name:master
@pdswan
pdswan / headers.txt
Created January 4, 2012 03:24
Open Congress Error
*Response Headers*
Date Wed, 04 Jan 2012 03:14:33 GMT
Server Apache/2.2.3 (CentOS)
X-Powered-By Phusion Passenger (mod_rails/mod_rack) 3.0.2
X-Runtime 0.976903
Status 500
Vary Accept-Encoding,User-Agent
Content-Encoding gzip
Content-Length 1267
Content-Type text/html; charset=UTF-8
@pdswan
pdswan / .watchr
Created March 22, 2011 01:18
Basic Watchr Rules and Actions
def run_spec(file)
unless File.exist?(file)
puts "#{file} does not exist"
return
end
puts "Running #{file}"
system "bundle exec rspec #{file}"
puts
end
@pdswan
pdswan / patch_through_belongs_to.rb
Created November 12, 2010 15:39
swaps the foreign key and primary key to fix has_many and has_one through belongs_to in Rails 2.3.x
class ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation
# has_many and has_one through belongs_to are broken becuase the order of the primary key
# and foreign table key need to be reversed. this detects and fixes it.
def association_join_with_through_belongs_to_fix
join = association_join_without_through_belongs_to_fix
if [:has_many, :has_one].include?(reflection.macro) && reflection.options[:through] && source_reflection.macro == :belongs_to
connection = reflection.active_record.connection
parent_table_name = connection.quote_table_name(parent.aliased_table_name)
parent_key = connection.quote_column_name(parent.primary_key)