code
stringlengths
1
1.73M
language
stringclasses
1 value
module SchedulesHelper def schedule_time_start_column(record) record.time_start.nil? ? "?" : sprintf("%04d",record.time_start) end def schedule_time_stop_column(record) record.time_stop.nil? ? "?" : sprintf("%04d",record.time_stop) end def schedule_recipient_column_attributes(record) if record.rec...
Ruby
module TestHelper end
Ruby
class CellCarrier < ActiveRecord::Base attr_accessible :format, :name end
Ruby
class TransportType < ActiveRecord::Base attr_accessible :name # ActiveScaffold CRUD-level restrictions def authorized_for_update? current_user.super_admin? end def authorized_for_create? current_user.super_admin? end def authorized_for_delete? current_user.super_admin? end end
Ruby
class Log < ActiveRecord::Base belongs_to :schedule belongs_to :volunteer belongs_to :orig_volunteer, :foreign_key => "orig_volunteer_id", :class_name => "Volunteer" belongs_to :donor, :class_name => "Location", :foreign_key => "donor_id" belongs_to :recipient, :class_name => "Location", :foreign_key => "reci...
Ruby
class Location < ActiveRecord::Base belongs_to :region geocoded_by :address, :latitude => :lat, :longitude => :lng # can also be an IP address acts_as_gmappable :process_geocoding => false, :lat => "lat", :lng => "lng", :address => "address" after_validation :geocode attr_accessible :region_id, :addres...
Ruby
class Assignment < ActiveRecord::Base belongs_to :volunteer belongs_to :region attr_accessible :admin # CRUD-level restrictions def authorized_for_update? current_user.admin or current_user.region_admin?(self.region) end def authorized_for_create? current_user.admin or current_user.region_admin?(...
Ruby
class Volunteer < ActiveRecord::Base belongs_to :transport_type belongs_to :cell_carrier has_many :assignments has_many :regions, :through => :assignments # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :...
Ruby
class FoodType < ActiveRecord::Base attr_accessible :name has_and_belongs_to_many :schedules # ActiveScaffold CRUD-level restrictions def authorized_for_update? current_user.super_admin? end def authorized_for_create? current_user.super_admin? end def authorized_for_delete? current_user.sup...
Ruby
class Schedule < ActiveRecord::Base belongs_to :volunteer belongs_to :prior_volunteer, :class_name => "Volunteer", :foreign_key => "prior_volunteer_id" belongs_to :donor, :class_name => "Location", :foreign_key => "donor_id" belongs_to :recipient, :class_name => "Location", :foreign_key => "recipient_id" belo...
Ruby
class Region < ActiveRecord::Base has_many :assignments has_many :volunteers, :through => :assignments geocoded_by :address, :latitude => :lat, :longitude => :lng # can also be an IP address after_validation :geocode attr_accessible :address, :lat, :lng, :name, :notes, :website, :handbook_url, :welcome_emai...
Ruby
class SchedulesController < ApplicationController before_filter :authenticate_volunteer! before_filter :admin_only, :only => [:fast_schedule,:today,:tomorrow,:yesterday,:edit,:update,:create,:new] def open index(nil,nil,"volunteer_id IS NULL and recipient_id IS NOT NULL") end def mine index(nil,curre...
Ruby
class CellCarriersController < ApplicationController before_filter :authenticate_volunteer! active_scaffold :cell_carrier do |conf| conf.columns = [:name,:format] end def create_authorized? current_volunteer.super_admin? end def update_authorized?(record=nil) current_volunteer.super_admin? en...
Ruby
class LogsController < ApplicationController before_filter :authenticate_volunteer! before_filter :admin_only, :only => [:today,:tomorrow,:yesterday,:being_covered,:tardy,:receipt,:new,:create] def mine_past index("volunteer_id = #{current_volunteer.id} AND \"when\" < current_date","My Past Shifts") end ...
Ruby
class TransportTypesController < ApplicationController before_filter :authenticate_volunteer! active_scaffold :transport_type do |conf| # if marking isn't enabled it creates errors on delete :( conf.actions.add :mark end def create_authorized? current_volunteer.super_admin? end def update_autho...
Ruby
class RegionsController < ApplicationController before_filter :authenticate_volunteer! active_scaffold :region do |conf| conf.columns = [:logo,:name,:title,:tagline,:address,:phone,:tax_id,:lat,:lng,:notes,:website] conf.update.columns = [:logo,:name,:title,:tagline,:address,:phone,:tax_id,:lat,:lng,:notes...
Ruby
class LocationsController < ApplicationController before_filter :authenticate_volunteer!, :except => [:hud] def hud @loc = Location.find(params[:id]) if (params[:key] == @loc.receipt_key) or current_volunteer.region_admin?(@loc.region) or current_volunteer.super_admin? @schedules = @loc.is_donor ? Sc...
Ruby
class FoodTypesController < ApplicationController before_filter :authenticate_volunteer! active_scaffold :food_type do |conf| conf.columns = [:name] # if marking isn't enabled it creates errors on delete :( conf.actions.add :mark end def create_authorized? current_volunteer.super_admin? end ...
Ruby
class AssignmentsController < ApplicationController before_filter :authenticate_volunteer! before_filter :admin_only def index @regions = Region.all if current_volunteer.super_admin? @my_admin_regions = @regions @my_admin_volunteers = Volunteer.all else @my_admin_regions = current_v...
Ruby
class ApplicationController < ActionController::Base protect_from_forgery ActiveScaffold.set_defaults do |config| config.security.current_user_method = :current_volunteer end layout :layout_by_resource protected def layout_by_resource if devise_controller? "custom_devise" else ...
Ruby
class VolunteersController < ApplicationController before_filter :authenticate_volunteer! before_filter :admin_only, :only => [:knight,:unassigned,:shiftless,:shiftless_old,:admin,:switch_user] def unassigned @filter = "(SELECT COUNT(*) FROM assignments a WHERE a.volunteer_id=volunteers.id)=0" @volunteer...
Ruby
class Notifier < ActionMailer::Base default :from => "robot@boulderfoodrescue.org" def region_welcome_email(region,volunteer) return nil if region.welcome_email_text.nil? or region.welcome_email_text.strip.length == 0 @welcome_email_text = region.welcome_email_text mail(:to => volunteer.email, :subject...
Ruby
#!/usr/bin/env rake # 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.expand_path('../config/application', __FILE__) Webapp::Application.load_tasks task(:generate_logs => :environment) do includ...
Ruby
source 'https://rubygems.org' gem 'rails' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' gem 'json' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~>...
Ruby
class InitRegionInLocations < ActiveRecord::Migration def up br = Region.where("name = ?","Boulder").shift Location.all.each{ |l| l.region = br l.save } end def down Location.all.each{ |l| l.region = nil } end end
Ruby
class AddSplashHtmlToRegion < ActiveRecord::Migration def change change_table :regions do |t| t.text :splash_html end end end
Ruby
class AddContactInfoToRegions < ActiveRecord::Migration def change change_table :regions do |t| t.string :phone t.string :tax_id end change_table :locations do |t| t.string :receipt_key end end end
Ruby
class CreateRegions < ActiveRecord::Migration def change create_table :regions do |t| t.decimal :lat t.decimal :lng t.string :name t.string :website t.text :address t.text :notes t.timestamps end end end
Ruby
class PopulateScheduleRegionAssignments < ActiveRecord::Migration def up br = Region.where("name = ?","Boulder").shift Schedule.all.each{ |s| s.region = br s.save } Log.all.each{ |l| l.region = br l.save } end def down Schedule.all.each{ |s| s.region = nil ...
Ruby
class AddTransportToSchedules < ActiveRecord::Migration def change add_column :schedules, :transport, :string end end
Ruby
class AddWaiverSignedToVolunteers < ActiveRecord::Migration def up add_column :volunteers, :waiver_signed, :boolean, :null => false, :default => 'f' add_column :volunteers, :waiver_signed_at, :datetime end def down remove_column :volunteers, :waiver_signed remove_column :volunteers, :waiver_signe...
Ruby
class AddTwitterStuffToRegion < ActiveRecord::Migration def change change_table :regions do |t| t.string :twitter_key t.string :twitter_secret t.string :twitter_token t.string :twitter_token_secret end end end
Ruby
class InitFoodTypesAndTransportTypes < ActiveRecord::Migration def up tthash = {} # Make sure these are in there to start... ["Bike","Car","Foot"].each{ |v| check = TransportType.where('name = ?',v) unless check.length >= 1 t = TransportType.new t.name = v t.save ...
Ruby
class AddIrregularToSchedule < ActiveRecord::Migration def change add_column :schedules, :irregular, :boolean add_column :schedules, :backup, :boolean end end
Ruby
class AddPhotoToVolunteers < ActiveRecord::Migration def up add_attachment :volunteers, :photo end def down remove_attachment :volunteers, :photo end end
Ruby
class AddWelcomeEmailTextToRegions < ActiveRecord::Migration def change change_table :regions do |t| t.text :welcome_email_text end end end
Ruby
class CreateLogs < ActiveRecord::Migration def change create_table :logs do |t| t.references :schedule t.date :when t.references :volunteer t.integer :orig_volunteer_id t.decimal :weight t.text :description t.string :transport t.text :notes t.integer :num_remi...
Ruby
class CreateVolunteers < ActiveRecord::Migration def change create_table :volunteers do |t| t.string :email t.string :name t.string :phone t.string :preferred_contact t.string :transport t.boolean :has_car t.text :admin_notes t.text :pickup_prefs t.date :gone_...
Ruby
class NewFieldsForRegion < ActiveRecord::Migration def up change_table :regions do |t| t.string :title t.string :tagline end add_attachment :regions, :logo end def down remove_column :regions, :title remove_column :regions, :tagline remove_attachment :regions, :logo end end
Ruby
class AddRegionToLocations < ActiveRecord::Migration def change change_table :locations do |t| t.references :region end end end
Ruby
class AddDeviseToVolunteers < ActiveRecord::Migration def self.up change_table(:volunteers) do |t| ## Database authenticatable #t.string :email, :null => false, :default => "" t.string :encrypted_password, :null => false, :default => "" ## Recoverable t.string :reset_...
Ruby
class UseFoodTypesAndTransportTypes < ActiveRecord::Migration def up create_table :food_types_schedules do |t| t.references :food_type t.references :schedule end change_table :logs do |t| t.references :transport_type t.references :food_type end change_table :schedules do |t...
Ruby
class AddPriorLbsRescuedToRegion < ActiveRecord::Migration def up change_table :regions do |t| t.integer :prior_lbs_rescued t.integer :prior_num_pickups end end def down remove_column :regions, :prior_lbs_rescued remove_column :regions, :prior_num_pickups end end
Ruby
class AddDonorAndRecipientToLog < ActiveRecord::Migration def change add_column :logs, :donor_id, :integer add_column :logs, :recipient_id, :integer end end
Ruby
class CreateLocations < ActiveRecord::Migration def change create_table :locations do |t| t.boolean :is_donor t.string :recip_category t.string :donor_type t.text :address t.string :name t.decimal :lat t.decimal :lng t.text :contact t.string :website t.t...
Ruby
class CreateFoodTypes < ActiveRecord::Migration def change create_table :food_types do |t| t.string :name t.timestamps end end end
Ruby
class AddAdminToVolunteers < ActiveRecord::Migration def change add_column :volunteers, :admin, :boolean, :default => false end end
Ruby
class MoveNeedsTrainingToVolunteer < ActiveRecord::Migration def up change_table :volunteers do |t| t.boolean :needs_training, :default => true end # if they've done a pickup successfully, they clearly don't need to be trained Log.where("weight is not NULL").each{ |l| next if l.volunteer.n...
Ruby
class AddHandbookLinkToRegion < ActiveRecord::Migration def change change_table :regions do |t| t.string :handbook_url end end end
Ruby
class PopulateAssignmentsAndRegions < ActiveRecord::Migration def up rb = Region.new rb.name = "Boulder" rb.address = "Boulder, Colorado, USA" rb.website = "http://boulderfoodrescue.org" rb.save rd = Region.new rd.name = "Denver" rd.address = "Denver, Colorado, USA" rd.website = "...
Ruby
class AddPreReminders < ActiveRecord::Migration def up change_table :volunteers do |t| t.boolean :pre_reminders_too, :default => false end end end
Ruby
class CreateSchedules < ActiveRecord::Migration def change create_table :schedules do |t| t.integer :recipient_id t.integer :donor_id t.references :volunteer t.integer :prior_volunteer_id t.integer :day_of_week t.integer :time_start t.integer :time_stop t.text :admi...
Ruby
class AddMoreTwitterStuff < ActiveRecord::Migration def change change_table :regions do |t| t.integer :twitter_last_poundage t.datetime :twitter_last_timestamp end end end
Ruby
class AssociateScheduleWithRegion < ActiveRecord::Migration def up change_table :schedules do |t| t.references :region end change_table :logs do |t| t.references :region end end def down remove_column :schedules, :region_id remove_column :logs, :region_id end end
Ruby
class AddTwitterStuffToLocation < ActiveRecord::Migration def change change_table :locations do |t| t.string :twitter_handle end end end
Ruby
class CreateAssignments < ActiveRecord::Migration def change create_table :assignments do |t| t.references :volunteer t.references :region t.boolean :admin t.timestamps end add_index :assignments, :volunteer_id add_index :assignments, :region_id end end
Ruby
class AddEmailToTextEmailToVolunteer < ActiveRecord::Migration def up create_table :cell_carriers do |t| t.string :name t.string :format end # These are taken from: http://www.emailtextmessages.com/ CellCarrier.create :name => "T-Mobile", :format => '%d@tmomail.net' CellCarrier.create...
Ruby
class VolunteersAddSncsBoolean < ActiveRecord::Migration def up add_column :volunteers, :get_sncs_email, :boolean, :null => false, :default => 'f' end def down remove_column :volunteers, :get_sncs_email end end
Ruby
class CreateTransportTypes < ActiveRecord::Migration def change create_table :transport_types do |t| t.string :name t.timestamps end end end
Ruby
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name =>...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Webapp::Application
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integrati...
Ruby
# Is sheet 01 (after the TOC) a left sheet or a right sheet? sheet1: right # "left" and "right" specify which page of a two-page spread a file # must start on. "left" means that a file must start on the first of # the two pages. "right" means it must start on the second of the two # pages. The file may start in eit...
Ruby
class CreateUsers < ActiveRecord::Migration def up create_table :users do |t| t.string :profile_id t.string :email t.string :refresh_token end add_index :users, :profile_id end def down drop_table :users end end
Ruby
# Copyright (C) 2012 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writ...
Ruby
source :gemcutter gem 'sinatra', :require => 'sinatra/base' gem 'thin', '~> 1.3' gem 'pg' gem 'sinatra-activerecord' gem 'google-api-client', '>= 0.4.4', :require => 'google/api_client' group :development do gem 'rake' gem 'sqlite3-ruby' end
Ruby
require 'sinatra.rb' # Sinatra defines #set at the top level as a way to set application configuration set :run, false set :env, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development) require './main' run Sinatra::Application
Ruby
require 'sinatra/activerecord/rake' require './main'
Ruby
# Is sheet 01 (after the TOC) a left sheet or a right sheet? sheet1: right # "left" and "right" specify which page of a two-page spread a file # must start on. "left" means that a file must start on the first of # the two pages. "right" means it must start on the second of the two # pages. The file may start in eit...
Ruby
# Is sheet 01 (after the TOC) a left sheet or a right sheet? sheet1: right # "left" and "right" specify which page of a two-page spread a file # must start on. "left" means that a file must start on the first of # the two pages. "right" means it must start on the second of the two # pages. The file may start in eit...
Ruby
# Is sheet 01 (after the TOC) a left sheet or a right sheet? sheet1: right # "left" and "right" specify which page of a two-page spread a file # must start on. "left" means that a file must start on the first of # the two pages. "right" means it must start on the second of the two # pages. The file may start in eit...
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
# 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
# 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
# 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
ActionController::Routing::Routes.draw do |map| map.root :controller => 'website', :action => 'index' map.wildcard "*wildcard", :controller => "website", :action => "not_found" # old revision: 198 end
Ruby
ENV['RAILS_ENV'] = 'production' require File.dirname(__FILE__)+'/config/environment' EmailQueue.send_all_email_in_queue
Ruby
load 'deploy' if respond_to?(:namespace) # cap2 differentiator Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } load 'config/deploy'
Ruby
xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do xml.title "BeyondRails" xml.description "BeyondRails Rails 中文 社区 博客 教程 资源 论坛" xml.link formatted_forums_url(:rss) for p in @rss_forums xml.item do xml.title h(p.title) xml.author h(p.user.login) ...
Ruby
xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do xml.title "BeyondRails" xml.description "BeyondRails Rails 中文 社区 博客 教程 资源 论坛" xml.link HOME + "/index.rss" for b in @blogs xml.item do xml.title h(b.title) xml.author h(b.user.login) xml.de...
Ruby
xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do xml.title "BeyondRails" xml.description "BeyondRails Rails 中文 社区 博客 教程 资源 论坛" xml.link formatted_tutorials_url(:rss) for t in @rss_tutorials xml.item do xml.title h(t.title) xml.author h(t.user.log...
Ruby
xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do xml.title "BeyondRails" xml.description "BeyondRails Rails 中文 社区 博客 教程 资源 论坛" xml.link formatted_blogs_url(:rss) for b in @rss_blogs xml.item do xml.title h(b.title) xml.author h(b.user.login) ...
Ruby
xml.instruct! :xml, :version => "1.0" xml.rss :version => "2.0" do xml.channel do xml.title "BeyondRails" xml.description "BeyondRails Rails 中文 社区 博客 教程 资源 论坛" xml.link formatted_resources_url(:rss) for r in @rss_resources xml.item do xml.title h(r.title) xml.author h(r.user.log...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def bbcode2html(text) text.gsub!(/\[code\]/i, "[code=ruby]") text.scan(/(\[code\=([a-z].+?)\](.+?)\[\/code\])/m).each do |match| text.gsub!(match[0],CodeRay.scan(match[2].strip, match[1].to_sy...
Ruby
class BlogComment < ActiveRecord::Base belongs_to :blog, :counter_cache => true belongs_to :user end
Ruby
class EmailQueue < ActiveRecord::Base def self.send_all_email_in_queue EmailQueue.find(:all, :order => "created_at asc").each do |email| ExceptionNotifier.deliver_sys_email(email.recipient, email.subject, email.content, email.content_type) email.destroy end end end
Ruby
class Blog < ActiveRecord::Base acts_as_taggable has_many :blog_comments belongs_to :user end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base # Virtual attribute for the unencrypted password attr_accessor :password validates_presence_of :login, :message => "用户名为必填项" validates_presence_of :email, :message => "Email为必填项" validates_presence_of :password, :message => "密码为必填项" valid...
Ruby
class Comment < ActiveRecord::Base belongs_to :forum, :counter_cache => true belongs_to :post, :counter_cache => true belongs_to :user end
Ruby
class Profile < ActiveRecord::Base end
Ruby
class Forum < ActiveRecord::Base has_many :posts has_many :comments attr_accessor :last_post end
Ruby
class Resource < ActiveRecord::Base acts_as_taggable belongs_to :user end
Ruby
class Post < ActiveRecord::Base acts_as_taggable belongs_to :forum, :counter_cache => true belongs_to :user has_many :comments attr_accessor :last_user end
Ruby
class Tutorial < ActiveRecord::Base acts_as_taggable belongs_to :user end
Ruby
class TutorialsController < ApplicationController before_filter :login_required, :only => [:new, :edit, :create, :update, :destroy] before_filter :set_current_menu_and_title def index @tutorials = Tutorial.paginate(:per_page => 10, :page => params[:page], :order => 'created_at desc') @rss_tutorials = Tu...
Ruby
class MyController < ApplicationController before_filter :login_required, :only => [:edit_avatar, :update_avatar] def index subdomain = request.subdomains[0] @user = User.find_by_login(subdomain) end def edit_avatar render :layout => false end def update_avatar avatar_path = params...
Ruby