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
/ How to get the iframe document object | |
// Assume 'iframe' is a variable to the iframe DOM element | |
var iframe_document = null; | |
if (iframe.contentDocument) iframe_document = iframe.contentDocument; | |
else if (iframe.contentWindow) iframe_document = iframe.contentWindow.document; | |
else if (iframe.document) iframe_document = iframe.document; | |
else throw(new Error("Cannot access iframe document.")); |
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
page1 = Proc.new do |pdf| | |
pdf.text "Hello World" | |
end | |
page2 = Proc.new do |pdf| | |
pdf.text "Chunky bacon!" | |
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
require "rubygems" | |
require "activerecord" | |
module New | |
class NewDatabase < ActiveRecord::Base | |
establish_connection( | |
:adapter => "mysql", |
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
context "failure due to record invalid" do | |
before(:each) do | |
e = mock("errors", :null_object => true) | |
e.stub!(:full_messages).and_return([]) | |
@obj.stub!(:errors).and_return(e) | |
@obj.stub!('update_attributes!').and_raise(ActiveRecord::RecordInvalid.new(@obj)) | |
put :update, { :id => @obj.id, at_name => @invalid_update } | |
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
module OnlineUsers | |
def count_online_users | |
User.count(:conditions => ["last_request_at > ?", 30.minutes.ago]) | |
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
# The original post by Yehuda says that code should go under config/preinitializer.rb, which can work if you are not running under Passenger | |
# that doesn't really gives a shit yet about preinitializer.rb, so you need to put this code at the bottom of your config/boot.rb not that the # Rails.boot! line should already be in your boot.rb file, it's just here for a position reference. | |
require "#{File.dirname(__FILE__)}/../vendor/bundler_gems/environment" | |
class Rails::Boot | |
def run | |
load_initializer | |
extend_environment |
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 Ability | |
include CanCan::Ability | |
# alias_action :index, :show, :to => :read | |
# alias_action :new, :to => :create | |
# alias_action :edit, :to => :update | |
def initialize(user) | |
if user.role? :admin | |
can :manage, :all |
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
def ticket_filter_links(status_name, user_id=nil) | |
if user_id.nil? | |
if status_name.downcase == 'closed' | |
content_tag(:li, link_to("All Closed Tickets", tickets_path + "?search[status_id_equals]=#{@closed_status.id}")) | |
else | |
content_tag(:li, link_to("All Active Tickets", tickets_path)) | |
end | |
else | |
if status_name.downcase == 'closed' | |
content_tag(:li, link_to("My Closed Tickets", tickets_path + "?search[status_id_equals]=#{@closed_status.id}&search[owned_by_equals]=#{user_id}")) |
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
#!/usr/bin/env ruby | |
# -*- ruby -*- | |
require 'rubygems' | |
require 'daemon-spawn' | |
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) | |
class DelayedJobWorker < DaemonSpawn::Base | |
def start(args) | |
ENV['RAILS_ENV'] ||= args.first || 'development' |
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
# If your workers are inactive for a long period of time, they'll lose | |
# their MySQL connection. | |
# | |
# This hack ensures we re-connect whenever a connection is | |
# lost. Because, really. why not? | |
# | |
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar) | |
# | |
# From: | |
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/ |
OlderNewer