Skip to content

Instantly share code, notes, and snippets.

@rwc9u
rwc9u / PULL_REQUEST_TEMPLAT.md
Created March 13, 2018 16:04
Pull Request Template

What does it do?

  • Item

What else do you need to know?

  • Item

Related Tickets

  • DIGITAL-XYZ

Screenshots

Image

Communication

(optional)

@rwc9u
rwc9u / add_index_patch.rb
Created June 19, 2012 07:57
Adding Index on Heroku without a Restart
module ActiveRecord::ConnectionAdapters::SchemaStatements
def add_index_with_quiet(table_name, column_names, options = {})
quiet = options.delete(:quiet)
add_index_without_quiet table_name, column_names, options
rescue
raise unless quiet and $!.message =~ /^Index name '.*' on table '#{table_name}' already exists/i
puts "Failed to create index #{table_name} #{column_names.inspect} #{options.inspect}"
end
alias_method_chain :add_index, :quiet
@rwc9u
rwc9u / address.rb
Created June 21, 2011 20:11
:accepts_nested_attributes_for with custom autosave
class Address < ActiveRecord::Base
has_many :phonings, :as => :phonable
has_many :phone_numbers, :through => :phonings
accepts_nested_attributes_for :phonings, :allow_destroy => true
end
@rwc9u
rwc9u / sample_models.rb
Created June 21, 2011 20:07
:accepts_nested_attributes_for with custom autosave
class Address < ActiveRecord::Base
has_many :phonings, :as => :phonable
has_many :phone_numbers, :through => :phonings
accepts_nested_attributes_for :phonings, :allow_destroy => true
end
class Person < ActiveRecord::Base
has_many :phonings, :as => :phonable

Rails 3 Design Choices - Jose Valim

SOLID Design Principles

Agile Software Development - Bob Martin Book is based on developing in Java/C… some interpretation for ruby.

Single Responsibility Open Closed - open for extension … closed for modification Liskov Substition

Rails 3 Design Choices - Jose Valim

SOLID Design Principles

Agile Software Development - Bob Martin Book is based on developing in Java/C… some interpretation for ruby.

Single Responsibility Open Closed - open for extension … closed for modification Liskov Substition

ruby-1.9.2-p136 :001 > j = Job.last
ruby-1.9.2-p136 :002 > j.file_data.file.gridio.class
=> Mongo::GridIO
ruby-1.9.2-p136 :003 > CSV.new(j.file_data.file.gridio)
NoMethodError: undefined method `pos' for #<GridIO _id: 4d5cbe235ef0dbcaf2000001>
from /Users/rchristie/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/csv.rb:2011:in `init_separators'
from /Users/rchristie/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/csv.rb:1570:in `initialize'
from (irb):3:in `new'
from (irb):3
from /Users/rchristie/dev/cast/vendor/ruby/1.9.1/gems/railties-3.0.4/lib/rails/commands/console.rb:44:in `start'
@rwc9u
rwc9u / irbrc
Created February 14, 2011 15:44
#-*-Ruby-*-
require 'rubygems'
require 'pp'
require 'wirble'
require 'hirb'
require 'ap'
if RUBY_VERSION[0..2] == "1.9"
require 'flyrb'
else
require 'utility_belt'
@rwc9u
rwc9u / gist:745337
Created December 17, 2010 17:37
Getting before_validations to run
# added a new before_validation
PhoneNumber.all { |p| p.save! }
# doesn't resave the data... silly me
ActiveRecord::Base.partial_updates = false
PhoneNumber.all { |p| p.valid?; p.save! }
klass = Paperclip::Storage::Filesystem
klass.module_eval do
def flush_writes #:nodoc:
logger.info("[paperclip-hack] Writing files for #{name}")
@queued_for_write.each do |style, file|
file.close
FileUtils.mkdir_p(File.dirname(path(style)))
logger.info("[paperclip-hack] -> #{path(style)}")
FileUtils.cp(file.path, path(style))