Skip to content

Instantly share code, notes, and snippets.

View adamrobbie's full-sized avatar

Adam Robbie adamrobbie

View GitHub Profile
@adamrobbie
adamrobbie / partial_async.rb
Created September 1, 2012 12:53
Render view asynchronously.
First put an empty, placeholder div in the main response
<div id="pink-dancing-elephants"></div>
and then add a little jQuery to the page
$.ajax({
url: "/elephants/dancing",
cache: false,
success: function(html){
$("#pink-dancing-elephants").append(html);
@adamrobbie
adamrobbie / Remote rep
Created November 4, 2012 12:55
Remotely create a github rep
curl -u 'USER:PASS' https://api.github.com/user/repos -d '{"name":"REPO"}'
git remote add origin [email protected]:USER/REPO.git
git push origin master
@adamrobbie
adamrobbie / Gemfile
Created November 13, 2012 15:28
Rails Endless pagination
gem 'will_paginate'
@adamrobbie
adamrobbie / application.rb
Created November 15, 2012 11:57
ActionMailer hook to intercept all outgoing development email
# Place me in config/application.rb or in your development file
if Rails.env.development?
class Hook
def self.delivering_email(message)
message.to = "\"#{message.to.first}\" <[email protected]>"
message.cc = nil if !message.cc.nil?
message.bcc = nil if !message.bcc.nil?
end
end
@adamrobbie
adamrobbie / gist:4235157
Created December 7, 2012 18:09
Heroku Secondary DB connection
# config/application.rb
module MyApp
class Application < Rails::Application
... other configs
config.secondary_database_url = ENV['SECONDARY_DB_URL']
end
end
We may want to override this in development / test
@adamrobbie
adamrobbie / string_to_bool.rb
Created January 18, 2013 15:17
Adds a to_bool method to Ruby's primitive String class, to convert to a boolean.
class String
def to_bool
return true if self == true || self =~ (/(true|t|yes|y|1)$/i)
return false if self == false || self.blank? || self =~ (/(false|f|no|n|0)$/i)
raise ArgumentError.new("invalid value for Boolean: \"#{self}\"")
end
end
module MiniTest
module Assertions
module ActiveRecord
# assert_association User, :has_many, :editables, :polymorphic => true
#
def assert_association(clazz, association, associate, options={})
reflected_assoc = clazz.reflect_on_association(associate)
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require File.dirname(__FILE__) + '/blueprints'
require 'faker'
require 'rails/test_help'
require 'minitest/autorun'
require 'minitest/pride'
class MiniTest::Unit::TestCase
include MiniTest::ActiveRecordAssertions
# == Paperclip without ActiveRecord
#
# Simple and lightweight object that can use Paperclip
#
#
# Customized part can be extracted in another class which
# would inherit from SimplePaperclip.
#
# class MyClass < SimplePaperclip
# attr_accessor :image_file_name # :<atached_file_name>_file_name
module SoftDeletable
extend ActiveSupport::Concern
def soft_delete!
find_each do |record|
record.soft_delete!
end
end
included do