Skip to content

Instantly share code, notes, and snippets.

View gist:8755
def create
only_provides :json
if params[:Filedata]
@photo = Photo.new_from_filedata(params[:Filedata])
if @photo.save
render '', :status => 200
else
raise NotAcceptable
end
else
View gist:8977
r.match('/designer/:photo_id/crop').name(:cropper) do |cropper|
cropper.match(:method => :get).to(:controller => 'crops', :action => 'new')
cropper.match(:method => :post).to(:controller => 'crops', :action => 'create')
end
View Items.rb
class Items < ActiveRecord::Base
def update
@item = Items.find(params[:id])
raise NotFound unless @item
if @item.update_attributes(params[:item])
redirect url(:item, item)
else
raise BadRequest
end
end
View gist:11991
RESULTS = %w(H H H H H H A A A A A D)
def result
RESULTS[rand(RESULTS.length)]
end
require 'readline'
def prompt(prompt="> ")
input = nil
@tooky
tooky / init.rb
Created Oct 20, 2008
workling.rb
View init.rb
Merb::BootLoader.after_app_loads do
config_path = Merb.root / 'config' / 'starling.yml'
load_path = Merb.root / 'app' / 'workers'
if File.exists?(config_path)
Workling::Client.options = YAML.load_file(config_path)[Merb.environment.to_sym]
Dir.glob(load_path / '**' / '*.rb').each { |wling| require wling }
else
Merb.logger.error! "No starling.yml file found in #{Merb.root}/config."
exit(1)
View gist:22550
# works
gem('activemerchant'); require 'active_merchant'
# fails with FATAL: The file activemerchant was not found
dependency('activemerchant') { require 'active_merchant' }
@tooky
tooky / Rakefile
Created Feb 5, 2009
Sinatra + Cucumber + Webrat
View Rakefile
require 'rubygems'
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "--format pretty"
end
View delegate.js
jQuery.fn.delegate = function(eventType, rules) {
return this.bind(eventType, function(e) {
var target = $(e.target);
for(var selector in rules)
if(target.is(selector))
return rules[selector].apply(this, arguments)
})
}
View gist:79000
require 'rubygems'
require 'sinatra'
require 'activerecord'
configure :development do
set :db, {:adapter => 'sqlite3', :dbfile => 'shout.dev.sqlite3.db'}
end
configure :production do
set :db, {:adapter => 'sqlite3', :dbfile => 'shout.sqlite3.db'}
View merb_paperclip.rb
# Monkeypatch paperclip 2.1.2 to work with merb
module Paperclip
class Attachment
def assign uploaded_file
%w(file_name).each do |field|
unless @instance.class.column_names.include?("#{name}_#{field}")
raise PaperclipError.new("#{self} model does not have required column '#{name}_#{field}'")
end
end