Skip to content

Instantly share code, notes, and snippets.

View carllerche's full-sized avatar
😎
working

Carl Lerche carllerche

😎
working
View GitHub Profile
describe '#save' do
describe 'with a new resource' do
it "should create when the resource is dirty" do
Zoo.new(:city => "San Diego").save
Zoo.first.name.should == "San Diego"
end
end
end
#!/usr/bin/env ruby
require 'rubygems'
require 'dm-core'
class Zoo
include DataMapper::Resource
property :id, Serial
end
@carllerche
carllerche / router.rb
Created September 22, 2008 03:56 — forked from fujin/gist:11935
Merb.logger.info("Compiling routes...")
Merb::Router.prepare do |r|
# This deferred route allows permalinks to be handled, without a separate rack handler
match("/:permalink").defer_to do |request, params|
unless (article = Article.find_by_permalink(params[:permalink)).nil?
{:controller => "articles", :action => "show", :id => article.id}
end
end
# Admin namespace
@carllerche
carllerche / router.rb
Created September 25, 2008 21:28 — forked from piclez/gist:12058
Merb::Router.prepare do |r|
#Merbauth routes is broken (capture is depricated)
slice(:MerbAuth, :path => "", :default_routes => false)
# This is the default route for /:controller/:action/:id
# This is fine for most cases. If you're heavily using resource-based
# routes, you may want to comment/remove this line to prevent
# clients from calling your create or destroy actions with a GET
default_routes
As a translation leader, you will maintain a fork of the book that represents
the authoritative status of the book in your language. Matt will then periodically
pull from your repository (or you can send him a pull request) when it is time to
update the master repository. You may then manage permissions to your repository
and give write permissions to anybody able to contribute in your language.
To set this up, do the following:
1. Fork the master repo (this is done via the github web interface).
2. Clone your fork of the repository to your local system:
@carllerche
carllerche / gist:42157
Created December 31, 2008 23:58 — forked from jm/gist:42156
# Put me in an initializer!
module ActionController
module Routing
class RouteSet
attr_accessor :routes
def initialize
@routes = []
@route_structure = {}
end
def create
@user = User.new
respond_with(@user) do
format.xml
format.html do
if @user.saved?
format.html { redirect_to(@user) }
else
render :action => "new"
end
# heredocs can continue the code on the same line:
class SomeController
def render opts
p opts
end
def setup; false; end
def action_a
###
clear_sources
bundle_path "vendor/bundler_gems"
bin_path "vendor/bin"
source "http://gemcutter.org"
source "http://gems.github.com"
gem "rails", "2.3.4", :only => :bundle
gem "clearance"
gem "will_paginate"
# sudo gem install rack nokogiri mongrel --no-rdoc --no-ri
# curl http://gist.github.com/raw/258378/31dc0cc39faf8328cc6b5b5e2fa2a973153f174d/gistfile1.txt > hello_world.rb
# ruby hello_world.rb
require 'rubygems'
require 'rack'
require 'nokogiri'
require 'open-uri'
class HelloWorld