This file contains hidden or 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
file 'Gemfile', <<-GEMS | |
source 'http://gemcutter.org' | |
gem "rails", "3.0.0.beta3" | |
gem "bson_ext", '0.20.1' | |
gem "mongoid", "2.0.0.beta4" | |
gem "compass", "0.10.0.rc5" | |
group :test do | |
gem "rspec-rails", "2.0.0.beta.8" | |
gem "capybara" |
This file contains hidden or 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 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" |
This file contains hidden or 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
# 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" |
This file contains hidden or 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 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 |
This file contains hidden or 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 referrer_must_be_existing_user | |
errors.add(:referral_id, "is not a valid user") if referral_id.blank? | |
end |
This file contains hidden or 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 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 |
This file contains hidden or 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 User < ActiveRecord::Base | |
... | |
def self.find_valid_referral(username) | |
user = User.find_by_username(username) | |
if user.nil? | |
nil | |
else | |
user.id | |
end | |
end |
This file contains hidden or 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 create | |
referral = User.find_by_username(params[:user][:referral]) | |
@user = User.new(params[:user].merge(:referral_id => referral.id)) | |
end |
This file contains hidden or 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 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 |
This file contains hidden or 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 Elder < ActiveRecord::Base | |
def self.increment_distribution_count(user_id) | |
self.find_by_user_id(user_id).increment!(:distribution_count) | |
end | |
end |