This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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}\" <my@email.com>" | |
message.cc = nil if !message.cc.nil? | |
message.bcc = nil if !message.bcc.nil? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'will_paginate' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -u 'USER:PASS' https://api.github.com/user/repos -d '{"name":"REPO"}' | |
git remote add origin git@github.com:USER/REPO.git | |
git push origin master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Controller | |
include LazyLoad | |
def show | |
@model = Model.find(...) | |
respond_to do |format| | |
format.html do | |
@html_specific_data = Model.find(...) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :db do | |
desc "Handle orphans" | |
task :handle_orphans => :environment do | |
Dir[Rails.root + "app/models/**/*.rb"].each do |path| | |
require path | |
end | |
ActiveRecord::Base.send(:descendants).each do |model| | |
model.reflections.each do |association_name, reflection| | |
if reflection.macro == :belongs_to | |
model.all.each do |model_instance| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AsyncHelper | |
def javascript_async(*args) | |
content_tag :script, type: "text/javascript" do | |
"(function() { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.async = true; | |
script.src = '#{j javascript_path(*args)}'; | |
var other = document.getElementsByTagName('script')[0]; |