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 paginate(collection, controller, action) | |
return if collection.empty? | |
if collection.total_pages > collection.per_page | |
html = 1.upto(collection.total_pages).map { |i| | |
options = { :page => i } | |
options.merge!(:q => params[:q]) if params[:q].present? | |
link_to(i, url(controller, action, options), :class => [(params[:page].to_i == i ? :current : :page), ' link']) | |
}.join | |
content_tag(:div, html, :class => "pagination") | |
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
def coderay(text) | |
return if text.nil? | |
text.gsub(/\<code( lang="(.+?)")?\>(.+?)\<\/code\>/m) do | |
content_tag("notextile", CodeRay.scan($3, $2).div(:css => :class)) | |
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/boot.rb | |
# Place this snippet right above the "Rails.boot!" command at the bottom of the file. | |
class Rails::Boot | |
def run | |
load_initializer | |
extend_environment | |
Rails::Initializer.run(:set_load_path) | |
end | |
def 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
# Load in required libraries | |
require 'rubygems' | |
require 'parseexcel' | |
# Load workbook into memory | |
workbook = Spreadsheet::ParseExcel.parse("file.xls") | |
# Open first worksheet | |
worksheet = workbook.worksheet(0) |
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 obtain_class | |
class_name = ENV['CLASS'] || ENV['class'] | |
raise "Must specify CLASS" unless class_name | |
@klass = Object.const_get(class_name) | |
end | |
def obtain_attachments | |
name = ENV['ATTACHMENT'] || ENV['attachment'] | |
raise "Class #{@klass.name} has no attachments specified" unless @klass.respond_to?(:attachment_definitions) | |
if !name.blank? && @klass.attachment_definitions.keys.include?(name) |
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
bundle=backup | |
app=myapp | |
heroku bundles:capture $bundle --app $app | |
sleep 15 | |
heroku bundles:download $bundle --app $app | |
heroku bundles:destroy $bundle --app $app |
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
## | |
# CarrierWave Amazon S3 File Reprocessor Rake Task | |
# | |
# Written (specifically) for: | |
# - CarrierWave | |
# - Ruby on Rails 3 | |
# - Amazon S3 | |
# | |
# Works with: | |
# - Any server of which you have write-permissions in the Rails.root/tmp directory |
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
## | |
# AttrAccessorBlock | |
# | |
# This module is to be "extended" (not included) into a class | |
# Then just invoke the "attr_accessor_block" method, like you would with "attr_accessor" | |
# This will enable you to make use of "block notations" and "instance_eval" to create "prettier" | |
# and more "readable" attribute setters. | |
# | |
# class Example | |
# extend AttrAccessorBlock |
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
// At the top of application.js | |
jQuery.ajaxSetup({ | |
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} | |
}) |