code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
class AddImageToIncentive < ActiveRecord::Migration
def self.up
add_column :incentives, :data, :binary # , :limit => 1.megabyte
add_column :incentives, :content_type, :string
add_column :incentives, :name, :string
end
def self.down
remove_column :incentives, :data, :content_type, :name
end
end
| Ruby |
class UserUpdate < ActiveRecord::Migration
def self.up
change_column(:users, :role, :string, :default => "lead")
end
def self.down
change_column(:users, :role, :string, :default => "runner")
end
end
| Ruby |
class InitialRelease < ActiveRecord::Migration
def self.create_site(name, desc)
Site.new({'name'=>name, 'description'=>desc, 'package_id'=>1, 'program_id'=>1}).save!
end
def self.up
User.new({'login'=>'KHooper','password'=>'KHooper','password_confirmation'=>'KHooper','site_id'=>'1','email'=>'email1@email.c... | Ruby |
class CreatePrograms < ActiveRecord::Migration
def self.up
create_table :programs do |t|
t.string :name
t.timestamps
end
end
def self.down
drop_table :programs
end
end
| Ruby |
class AddPackageToSite < ActiveRecord::Migration
def self.up
add_column :sites, :package_id, :int
end
def self.down
remove_column :sites, :package_id
end
end
| Ruby |
class CreateRunners < ActiveRecord::Migration
def self.up
create_table :runners do |t|
t.integer :group_id
t.string :first_name
t.string :last_name
t.string :gender
t.date :birthdate
t.integer :level
t.string :shirt_size
t.integer :shoe_size
t.d... | Ruby |
class AddThumbnailsToLandmarks < ActiveRecord::Migration
def self.up
add_column :landmarks, :content_type, :string
add_column :landmarks, :filename, :string
add_column :landmarks, :size, :integer
add_column :landmarks, :width, :integer
add_column :landmarks, :height, :integer
end
def self.dow... | Ruby |
class AdditionalPermissions < ActiveRecord::Migration
def self.create_permission(name, role, level)
Permission.new({'name'=>name, 'role'=>role, 'level'=>level}).save!
end
def self.destroy_permission(name, role, level)
thing = Permission.find_by_name_and_role_and_level(name,role,level)
thing.destroy
... | Ruby |
class CreateSites < ActiveRecord::Migration
def self.up
create_table :sites do |t|
t.integer :program_id
t.string :name
t.string :description
t.timestamps
end
end
def self.down
drop_table :sites
end
end
| Ruby |
class DefaultAuth < ActiveRecord::Migration
def self.create_permission(name, role, level)
Permission.new({'name'=>name, 'role'=>role, 'level'=>level}).save!
end
def self.up
User.new({'login'=>'super','password'=>'super','password_confirmation'=>'super', 'email'=>'super@email.com', 'role'=>'super'}).sav... | Ruby |
class CreateIncentiveImages < ActiveRecord::Migration
def self.up
create_table :incentive_images do |t|
t.integer :incentive_id, :parent_id, :size, :width, :height
t.string :content_type, :filename, :thumbnail
t.timestamps
end
remove_column :incentives, :data
remove_column :inc... | Ruby |
class TieUsersToGroups < ActiveRecord::Migration
def self.up
add_column :groups, :user_id, :integer
add_column :users, :site_id, :integer
end
def self.down
remove_column :groups, :user_id
remove_column :users, :site_id
end
end
| Ruby |
class ChangePermissionsAllow < ActiveRecord::Migration
def self.create_permission(name, role, level)
Permission.new({'name'=>name, 'role'=>role, 'level'=>level}).save!
end
def self.destroy_permission(name, role, level)
thing = Permission.find_by_name_and_role_and_level(name,role,level)
thing.destroy
... | Ruby |
class CreateIncentives < ActiveRecord::Migration
def self.up
create_table :incentives do |t|
t.integer :package_id
t.integer :goal
t.text :reward
t.timestamps
end
end
def self.down
drop_table :incentives
end
end
| Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table "users", :force => true do |t|
t.column :login, :string
t.column :email, :string
t.column :crypted_password, :string, :limit => 40
t.column :salt, :str... | Ruby |
class CreateRouteSiteJoinTable < ActiveRecord::Migration
def self.up
create_table :routesites do |t|
#note that order is not unique for table,
#but unique for site
t.integer :order
t.references :site
t.references :route
end
end
def self.down
drop_table :routesite
end
end
| Ruby |
class CreateRoutes < ActiveRecord::Migration
def self.up
create_table :routes do |t|
t.string :name
t.text :description
# for uploads
t.string :content_type
t.string :filename
t.integer :size
t.integer :width
t.integer :height
t.timestamps
end
end
d... | Ruby |
class CreatePermissions < ActiveRecord::Migration
def self.up
create_table :permissions do |t|
t.string :name
t.string :role
t.integer :level
end
add_column :users, :role, :string, :default => 'runner'
end
def self.down
drop_table :permissions
remove_column :user... | Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class Test::Unit::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
# test datab... | Ruby |
#!/opt/local/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai... | Ruby |
#!/opt/local/bin/ruby
#
# You may specify the path to the FastCGI crash log (a log of unhandled
# exceptions which forced the FastCGI instance to exit, great for debugging)
# and the number of requests to process before running garbage collection.
#
# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.lo... | Ruby |
#!/opt/local/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai... | Ruby |
#!/opt/local/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai... | Ruby |
#!/opt/local/bin/ruby
#
# You may specify the path to the FastCGI crash log (a log of unhandled
# exceptions which forced the FastCGI instance to exit, great for debugging)
# and the number of requests to process before running garbage collection.
#
# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.lo... | Ruby |
#!/opt/local/bin/ruby
require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT)
# If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like:
# "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impai... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/about'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require 'csv'
require 'config/environment'
require 'lib/group_excel'
#
# This script takes 1 argument, locaction of XLS files which contain the student rosters
# If any errors occur, it will notify you on the screen
# The only assumption is that all the csv files are student roster files
# T... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/about'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/plugin'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/spawner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/spawner'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/inspector'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/reaper'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/reaper'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/process/inspector'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/request'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../../config/boot'
require 'commands/performance/request'
| Ruby |
#!/usr/bin/env ruby
require 'csv'
require 'config/environment'
require 'lib/group_excel'
#
# This script takes 1 argument, locaction of XLS files which contain the student rosters
# If any errors occur, it will notify you on the screen
# The only assumption is that all the csv files are student roster files
# T... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/generate'
| Ruby |
module ApplicationHelper
def page_level_messages
messages = ''
for message_type in [:error, :notice]
if flash[message_type]
messages << content_tag('div', content_tag('p',flash[message_type], :class => message_type), :class => 'page_message', :id => "page_message_#{message_type}")
end
... | Ruby |
module AccountHelper
end | Ruby |
module IncentivesHelper
def image_for(incentive, size = nil)
if incentive.incentive_image
image = incentive.incentive_image.public_filename(size)
image_tag(image)
else
image_tag("missing-image-#{size}.png")
end
end
end
| Ruby |
module UsersHelper
end
| Ruby |
module MapHelper
# don't forget endmapsetup
def startmapsetup
@index = 0 if @index.nil? #set default
output = '<script src="http://maps.google.com/maps?file=api&v=2&key=' + @program.gmapapi + '&sensor=false" type="text/javascript"></script>' + "\n"
output += '<script type="text/javascript">'+"\n"
output += <<daEND... | Ruby |
class Runner < ActiveRecord::Base
belongs_to :group
has_one :user
has_many :entries
validates_presence_of :group_id
validates_presence_of :first_name
validates_presence_of :last_name
validates_numericality_of :goal
validates_numericality_of :shoe_size, :message => "must be a number."
validates_inclu... | Ruby |
class Incentive < ActiveRecord::Base
belongs_to :package
has_one :incentive_image, :dependent => :destroy
validates_presence_of :package
validates_presence_of :goal
validates_presence_of :reward
# validates_format_of :content_type,
# :with => /^image/,
# :messa... | Ruby |
require 'common'
class Site < ActiveRecord::Base
belongs_to :program
has_many :groups
has_many :users
belongs_to :package
has_many :routesite
has_many :routes, :through => :routesite
validates_presence_of :name
after_save :update_caches_for_program
after_destroy :update_caches_for_program
after_... | Ruby |
class UserObserver < ActiveRecord::Observer
def after_create(user)
UserNotifier.deliver_signup_notification(user)
end
def after_save(user)
UserNotifier.deliver_activation(user) if user.recently_activated?
end
end | Ruby |
class Entry < ActiveRecord::Base
belongs_to :runner
validates_numericality_of :distance, :message => ': Distance ran must be a number'
validates_numericality_of :sessions, :message => ': Sessions ran must be a number'
validate :Distance_must_be_greater_then_0
after_save :update_caches_for_runner
after... | Ruby |
class Landmarks < ActiveRecord::Base
belongs_to :package
validates_presence_of :lat
validates_presence_of :lng
validates_presence_of :name
validates_presence_of :description
has_attachment :content_type => :image,\
:storage => :file_system,\
# high limit, but these are resized pretty small
:max_s... | Ruby |
class Program < ActiveRecord::Base
has_many :sites
validates_presence_of :name
# validates_length_of :website, :within => 10..100
def percent_complete
return calc_percent_complete(distance_cache, goal_cache)
end
def update_caches!
distance = 0
sessions = 0
goal = 0
runners = 0
... | Ruby |
require 'digest/sha1'
class User < ActiveRecord::Base
# Virtual attribute for the unencrypted password
attr_accessor :password
belongs_to :site
belongs_to :runner
has_many :groups
validates_presence_of :login
validates_presence_of :email, :if => :not_student?
validates_presence_of ... | Ruby |
class IncentiveImage < ActiveRecord::Base
belongs_to :incentive
has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 500.kilobytes,
:resize_to => '384x256>',
:thumbnails => {
:large => '96x9... | Ruby |
class Permission < ActiveRecord::Base
belongs_to :user
def level_name()
d = { 1 => :global,
2 => :site,
3 => :group,
4 => :self }
return d[self.level]
end
end
| Ruby |
class Route < ActiveRecord::Base
validates_presence_of :name
has_many :routesite
has_many :sites, :through => :routesite
has_attachment :storage => :file_system, :path_prefix=>"public/route_files", :content_type => 'application/vnd.google-earth.kml+xml'
validates_as_attachment
def updateSiteRoute(site,order)
... | Ruby |
class Routesite < ActiveRecord::Base
belongs_to :route
belongs_to :site
named_scope :defaultsiteroutes, :order => '"order" DESC', :conditions => {:site_id => '-1'}
named_scope :dbsiteroutes, lambda { |site| {:order => '"order" DESC',:conditions => ['site_id = ?',site.id]}}
def self.defaults
#not sure why this h... | Ruby |
class IncentiveService
attr_reader :incentive, :incentive_image
def initialize(incentive, incentive_image)
@incentive = incentive
@incentive_image = incentive_image
end
def save
return false unless valid?
begin
Incentive.transaction do
if @incentive_image.new_record?
... | Ruby |
require 'common'
class Group < ActiveRecord::Base
belongs_to :site
has_many :runners
has_one :user
validates_presence_of :name
validates_presence_of :description
validates_presence_of :site_id
after_save :update_caches_for_site
after_destroy :update_caches_for_site
after_update :update_caches_for_... | Ruby |
class UserNotifier < ActionMailer::Base
def signup_notification(user)
setup_email(user)
@subject += 'Please activate your new account'
@body[:url] = "http://YOURSITE/account/activate/#{user.activation_code}"
end
def activation(user)
setup_email(user)
@subject += 'Your account has bee... | Ruby |
class Package < ActiveRecord::Base
has_many :incentives
end
| Ruby |
class IncentivesController < ApplicationController
def index
@incentives = Incentive.find(:all, :order => "package_id, goal")
end
def picture
@incentive = Incentive.find(params[:id])
send_data(@incentive.data,
:filename => @incentive.name,
:type => @incentive.content_... | Ruby |
class RoutesController < ApplicationController
def index
@routes = Route.find(:all)
end
def new
@route = Route.new
end
def create
@route = Route.new(params[:route])
return self.unauthorized unless self.current_user.can('create:route', @route)
if @route.save
flash[:notice] = 'New route successfully ... | Ruby |
class RunnersController < ApplicationController
def index
if @group
return self.unauthorized unless self.current_user.can('view:group', @group)
@runners = @group.runners
else
@runners = Runner.find(:all)
end
end
def show
@runner = Runner.find(params[:id])
return self.unauth... | Ruby |
class AccountController < ApplicationController
def index
redirect_to(:action => 'login') unless logged_in? || User.count > 0
end
def login
return unless request.post?
self.current_user = User.authenticate(params[:login], params[:password])
if logged_in?
if params[:remember_me] == "1"
... | Ruby |
class LandmarksController < ApplicationController
def index
@landmarks = Landmarks.find(:all, :order => "package_id")
end
def new
@landmark = Landmarks.new
end
def edit
@landmark = Landmarks.find(params[:id])
return self.unauthorized unless self.current_user.can('edit:landmark', @landmark)
... | Ruby |
class EntriesController < ApplicationController
def index
if @runner
return self.unauthorized unless self.current_user.can('view:entries', @runner)
@entries = @runner.entries
else
# i don't think this will ever be a case, or shouldn't be - nick
# i can't really put a permission on v... | Ruby |
class SitesController < ApplicationController
def show
@site = Site.find(params[:id])
return self.unauthorized unless self.current_user.can('view:site', @site)
@groups = @site.groups
add_page_token(@site.name)
end
def new
return self.unauthorized unless self.current_user.can('create:site', n... | Ruby |
class HomeController < ApplicationController
def home
if (self.current_user.respond_to?("is_not_student?")) && (not self.current_user.is_not_student?)
@runner = self.current_user.get_runner
add_page_token(@runner.name + "'s Map")
@is_student = true
# next two probably should be combined to one db ... | Ruby |
class UsersController < ApplicationController
def index
page = params[:page] || 1
@users = User.paginate :page => page, :order => 'login', :per_page => 100
end
def new
@user = User.new
end
def edit
@user = User.find(params[:id])
return self.unauthorized unless self.current_user.can('ed... | Ruby |
class ApplicationController < ActionController::Base
include RenderTools
include AuthenticatedSystem
before_filter :login_from_cookie
before_filter :before_render_tools
before_filter :setup
after_filter :after_render_tools
helper :all
# See ActionController::RequestForgeryProtection for details
#... | Ruby |
class TrophyRoomsController < ApplicationController
def show
count=5
@runner = Runner.find(params[:id])
return self.unauthorized unless self.current_user.can('view:runner', @runner)
# package_id = @runner.package.id
if (not @runner.blank?)
@distance = @runner.distance_cache
@incentives ... | Ruby |
class GroupsController < ApplicationController
layout "application", :except => [ :report ]
def show
@group = Group.find(params[:id])
return self.unauthorized unless self.current_user.can('view:group', @group)
@runners = @group.runners
add_page_token(@group.name)
end
def map
@group = Group... | Ruby |
class ProgramsController < ApplicationController
skip_before_filter :setup, :only => [:new, :create]
before_filter :ensure_application_has_one_program, :only => [:new, :create, :destroy]
def index
@programs = Program.find(:all)
end
def show
@program = Program.find(params[:id])
@sites = @program... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# i... | Ruby |
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Store the full class name (including module namespa... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
| Ruby |
ActionController::Routing::Routes.draw do |map|
map.resources :programs
map.resources :sites
map.resources :groups
map.resources :runners
map.resources :entries
map.resources :incentives
map.resources :landmarks
map.resources :routes
map.resources :users
# The priority is based upon order of c... | Ruby |
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end
def booted?
... | Ruby |
# Be sure to restart your server when you modify this file
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.1... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Full error repor... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.ca... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between... | Ruby |
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
| Ruby |
module AuthenticatedSystem
class FakeUser
def can(capability, object)
return self.can?(capability, object)
end
end
class AnonymousUser < FakeUser
def site_id
return nil
end
def site
return nil
end
def can?(capability, object)
return false
... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.