Skip to content

Instantly share code, notes, and snippets.

class ActionDuck
attr_accessor :errors
def initialize(h)
h ||= {}
h.each { |k,v| send("#{k}=", v) }
self.errors = ActiveRecord::Errors.new(self)
end
module ShouldaContextExtensions
def self.included(base)
base.class_eval do
alias_method_chain :build, :fast_context
alias_method_chain :am_subcontext?, :fast_context
end
end
def fast_context(name, &blk)
@fast_subcontexts ||= []
@pacoguzman
pacoguzman / gist:217606
Created October 24, 2009 16:07 — forked from dhh/gist:45076
# 1) Point *.example.com in your DNS setup to your server.
#
# 2) Setup an Apache vhost to catch the star pointer:
#
# <VirtualHost *:80>
# ServerName example.com
# ServerAlias *.example.com
# </VirtualHost>
#
# 3) Set the current account from the subdomain
document.observe("dom:loaded", function() {
function updateElementsWithTime() {
$$("span[time]").invoke('updateTime')
}
// update immediately
updateElementsWithTime()
// continue updating every 2 minutes
new PeriodicalExecuter(updateElementsWithTime, 60 * 2)
})
document.observe("dom:loaded", function() {
function updateElementsWithTime() {
$$("span[time]").invoke('updateTime')
}
// update immediately
updateElementsWithTime()
// continue updating every 2 minutes
new PeriodicalExecuter(updateElementsWithTime, 60 * 2)
})
# More "proper" than a miniskirt (http://gist.github.com/273579).
class Minidress
@@factories = {}
class << self
def define(name, &block)
@@factories[name.to_s] = block
end
def build(name, attrs = {})
new(name.to_s.classify.constantize.new, &@@factories[name.to_s]).record
# Factory girl, relaxed.
#
# Factory.define :user do |f|
# f.login 'johndoe%d' # Sequence.
# f.email '%{login}@example.com' # Interpolate.
# f.password f.password_confirmation('foobar') # Chain.
# end
#
# Factory.define :post do |f|
# f.user { Factory :user } # Blocks, if you must.
# Directly copied from eycap-0.5.2 (thanks!)
#
# With these tasks you can:
# - dump your production database and save it in shared_path/db_backups
# - dump your production into your local database (clone_to_local)
#
# Right now is not tested without all the gem. Give me a moment to check it :-)
Capistrano::Configuration.instance(:must_exist).load do
namespace :db do
@pacoguzman
pacoguzman / rails_3_beta2_changes
Created April 2, 2010 10:29 — forked from ryanb/rails_3_beta2_changes
Rails3 Beta 2 changes
Action Pack
* Remove metal from Rails3 [YK]
http://github.com/rails/rails/commit/45e60283e733a535d68d499aa20e095c905f43b0
* :only and :except options in the use of rack middlewares [JV]
http://github.com/rails/rails/commit/9a93844aba44319d3c8487a554124beb00ccc267
class PostsController < ApplicationController
use AutheMiddleware, :except => [:index, :show]
Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end