Skip to content

Instantly share code, notes, and snippets.

class SomeController < ApplicationController
layout "some_layout", :only => [:new, :edit]
...
end
#=> renders all actions, other than new and edit, with no layout.
class SomeController < ApplicationController
def edit
...
render :layout => "some_layout"
# mongo_template.rb
# fork of Ben Scofield's Rails MongoMapper Template (http://gist.github.com/181842)
#
# To use:
# rails project_name -m http://gist.github.com/gists/219223.txt
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
class User < ActiveRecord::Base
validate_on_create :referrer_must_be_existing_user
...
def self.find_valid_referral(username)
case
when username.blank? then Elder.first(:group => "distribution_count ASC").user_id
when !username.blank? && self.exists?(:username => username) then User.find_by_username(username).id
else nil
end
end
class User < ActiveRecord::Base
...
def self.find_valid_referral(username)
user = User.find_by_username(username)
if user.nil?
nil
else
user.id
end
end
def create
referral = User.find_by_username(params[:user][:referral])
@user = User.new(params[:user].merge(:referral_id => referral.id))
end
def referrer_must_be_existing_user
errors.add(:referral_id, "is not a valid user") if referral_id.blank?
end
def self.find_valid_referral(username)
case
when username.blank? then EarlyAdopter.first(:group => "distribution_count ASC").user_id
when !username.blank? && self.exists?(:username => username) then User.find_by_username(username).id
else nil
end
end
class UsersController < ApplicationController
...
def create
referral_id = User.find_valid_referral(params[:user][:referral])
@user = User.new(params[:user].merge(:referral_id => referral_id))
...
end
...
end
class Elder < ActiveRecord::Base
def self.increment_distribution_count(user_id)
self.find_by_user_id(user_id).increment!(:distribution_count)
end
end
@erichurst
erichurst / Geo.js
Created March 16, 2010 21:03 — forked from kara-ryli/Geo.js
var Geo = navigator.geolocation, // {Object|null} a shortcut to the geolocation static class
options = { // {Object} options available to calls for position
enableHighAccuracy: false, // {Boolean} Whether or not to use more resources to get a more accurate position
maximumAge: 0, // {Number|Infinity} The maximum number of milliseconds since the last check.
timeout: null // {Number|null} The maximum number of milliseconds to wait for a fix
},
watchId; // {Number} an ID to a watch timeout
// handles an error finding the user's position
function onError(error) {