Skip to content

Instantly share code, notes, and snippets.

@tansengming
tansengming / Rails Console Actionmailer test.rb
Created April 24, 2009 15:14
Rails Console Actionmailer test
# Copy and paste this to the rails console to test your email settings
class MyMailer < ActionMailer::Base
def test_email
@recipients = "someone@somewhere.com"
@from = "must_be_same_as_smpt_account_login@gmail.com"
@subject = "test from the Rails Console"
@body = "This is a test email"
end
end
@r00k
r00k / gist:906356
Created April 6, 2011 19:33
Custom devise strategy
# In config/initializers/local_override.rb:
require 'devise/strategies/authenticatable'
module Devise
module Strategies
class LocalOverride < Authenticatable
def valid?
true
end
@hidakatsuya
hidakatsuya / thinreports-example-advanced-list.rb
Created August 17, 2011 06:51
ThinReports Example: Advanced List
# coding: utf-8
require 'rubygems'
require 'thinreports'
report = ThinReports::Report.new :layout => 'advanced_list'
report.layout.config.list(:advanced_list) do
# Define the variables used in list.
use_stores :row_count => 0,
@wicz
wicz / bootstrap.sh
Created April 9, 2013 13:28
Configuration files and scripts for the blog post: Faster Rails 3 deployments to AWS Elastic Beanstalk http://horewi.cz/faster-rails-3-deployments-to-aws-elastic-beanstalk.html
#!/usr/bin/env bash
mkdir /var/app/ondeck/vendor /var/app/ondeck/public /var/app/support/bundle /var/app/support/assets /var/app/support/cache
ln -s /var/app/support/bundle /var/app/ondeck/vendor
ln -s /var/app/support/assets /var/app/ondeck/public
ln -s /var/app/support/cache /var/app/ondeck/vendor
sed -i 's/"rake/"bundle exec rake/' /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh
@turadg
turadg / subdomains.rb
Last active January 21, 2024 19:45 — forked from rtekie/subdomains.rb
Drop-in utility to test your app subdomains with Capybara, Rspec, and a Javascript driver (Poltergeist, Webkit, or Selenium)
# Support for Rspec / Capybara subdomain integration testing
# Make sure this file is required by spec_helper.rb
# (e.g. save as spec/support/subdomains.rb)
def switch_to_subdomain(subdomain)
# lvh.me always resolves to 127.0.0.1
hostname = subdomain ? "#{subdomain}.lvh.me" : "lvh.me"
Capybara.app_host = "http://#{hostname}"
end
@micahroberson
micahroberson / estimate.rb
Created July 13, 2013 00:35
Generate and save a pdf to S3 with wicked_pdf and paperclip
# Main reference was lascarides' post at http://stackoverflow.com/questions/14743447/getting-pdf-from-wickedpdf-for-attachment-via-carrierwave
# estimate.rb
# ...
has_attached_file :pdf,
storage: :s3,
s3_credentials: {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
bucket: ENV['AWS_BUCKET']
@SabretWoW
SabretWoW / rspec_model_testing_template.rb
Last active March 7, 2024 03:56
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@mattheworiordan
mattheworiordan / application.rb
Created March 28, 2014 09:05
CloudFlare IP Middleware for Rails to ensure HTTP_CF_CONNECTING_IP is used and the clients IP is correct within Rails
module RailsAppName
class Application < Rails::Application
# .... your settings
require "#{Rails.root}/lib/cloud_flare_middleware"
config.middleware.insert_before(0, Rack::CloudFlareMiddleware)
# ... your settings
end
end
module LiquidPresenters
class Plan < SimpleDelegator
def to_liquid
@to_liquid ||= HashWithIndifferentAccess.new({
id: self.id,
name: self.name,
description: self.description,
status: self.status,
class_id: self.plan_class_id
})
@gcarrion-gfrmedia
gcarrion-gfrmedia / 0000_packages.config
Created April 29, 2014 10:49
AWS Elastic Beanstalk Ruby 2.0/Puma Environment - .ebextensions tweaks and Sidekiq configuration. This is known to work fine with AWS Elastic Beanstalk 's 64bit Amazon Linux 2014.03 v1.0.1 running Ruby 2.0 (Puma) stack. Later stack versions might not work, but for that specific version works fine.
# Install Git needed for Git based gems
packages:
yum:
git: []