code
stringlengths
1
1.73M
language
stringclasses
1 value
# Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use yo...
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
# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attac...
Ruby
# Be sure to restart your server when you modify this file. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters ...
Ruby
# Be sure to restart your server when you modify this file. Example::Application.config.session_store :cookie_store, key: '_example_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rails g...
Ruby
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying to debug a probl...
Ruby
Example::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action...
Ruby
Example::Application.configure do # Settings specified here will take precedence over those in config/application.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 web se...
Ruby
Example::Application.configure do # Settings specified here will take precedence over those in config/application.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 su...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Example::Application.initialize!
Ruby
require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' if defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.requi...
Ruby
Example::Application.routes.draw do resources :posts do resources :vote, :only => [:update] do delete 'clear' end end devise_for :users root :to => "posts#index" # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match ...
Ruby
module ApplicationHelper def resource_name :user end def resource @resource ||= User.new end def devise_mapping @devise_mapping ||= Devise.mappings[:user] end end
Ruby
module VoteHelper end
Ruby
module PostsHelper end
Ruby
class UsersRole < ActiveRecord::Base belongs_to :role belongs_to :user end
Ruby
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable before_create :create_role devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable...
Ruby
class UsersVote < ActiveRecord::Base belongs_to :user belongs_to :vote end
Ruby
class Ability include CanCan::Ability def initialize(user) user ||= User.new if user.role? :admin can :manage, Post can :clear, Vote else can :read, :all if user.role?(:user) can :create, Post can :update, Post do |post| post.try(:user) == user ...
Ruby
class Vote < ActiveRecord::Base belongs_to :post has_many :users_votes has_many :users, :through => :users_votes end
Ruby
class Role < ActiveRecord::Base has_many :users_roles has_many :users, :through => :users_roles end
Ruby
class Post < ActiveRecord::Base after_create :create_vote belongs_to :user has_one :vote, :dependent => :destroy validates :title, :content, :presence => true protected def create_vote self.vote = Vote.create(:score => 0) end end
Ruby
class PostsController < ApplicationController load_and_authorize_resource # GET /posts # GET /posts.json def index @posts = Post.all respond_to do |format| format.html # index.html.erb format.json { render json: @posts } end end # GET /posts/1 # GET /posts/1.json def show ...
Ruby
class VoteController < ApplicationController load_and_authorize_resource def update post = Post.find(params[:post_id]) vote = post.vote vote.score += 1 if params[:vote][:score] == "Up" vote.score -= 1 if params[:vote][:score] == "Down" vote.users << current_user vote.save fla...
Ruby
class ApplicationController < ActionController::Base protect_from_forgery rescue_from CanCan::AccessDenied do |exception| flash[:error] = "Access"#exception.message redirect_to root_url end end
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__) Example::Application.load_tasks
Ruby
#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
source 'https://rubygems.org' gem 'rails', '3.2.1' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' # 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', '~> 3...
Ruby
class CreateVotes < ActiveRecord::Migration def change create_table :votes do |t| t.integer :score t.references :post end end end
Ruby
class CreateRoles < ActiveRecord::Migration def change create_table :roles do |t| t.string :name end end end
Ruby
class DeviseCreateUsers < ActiveRecord::Migration def change create_table(:users) do |t| ## Database authenticatable t.string :email, :null => false, :default => "" t.string :encrypted_password, :null => false, :default => "" ## Recoverable t.string :reset_password_to...
Ruby
class AddReferneces < ActiveRecord::Migration def change change_table :users_votes do |f| f.references :user f.references :vote end end end
Ruby
class CreateUsersRoles < ActiveRecord::Migration def change create_table :users_roles do |t| t.references :user t.references :role t.timestamps end end end
Ruby
class CreateUsersVotes < ActiveRecord::Migration def change create_table :users_votes do |t| t.timestamps end end end
Ruby
class CreatePosts < ActiveRecord::Migration def change create_table :posts do |t| t.string :title t.text :content t.references :user t.timestamps end add_index :posts, :user_id 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: 'Emanuel...
Ruby
FactoryGirl.define do factory :role do name "user" end end
Ruby
FactoryGirl.define do factory :post do sequence(:title) {|n| "New Title -- #{n}" } content "MyText" user end end
Ruby
# Read about factories at http://github.com/thoughtbot/factory_girl FactoryGirl.define do factory :users_vote do end end
Ruby
FactoryGirl.define do factory :user do sequence(:email) {|n| "email#{n}@abc.com" } password "1234567" end end
Ruby
# Read about factories at http://github.com/thoughtbot/factory_girl FactoryGirl.define do factory :vote do score 0 end end
Ruby
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' require 'rspec/autorun' require "cancan/matchers" # Requires supporting ruby files with custom matchers and macros, etc, # in spec/...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Example::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
require 'yaml' unless File.exists? "build.yml" puts "Cannot find build.yml" exit 1 end $app_config = YAML::load_file("build.yml") $app_path = File.expand_path(File.dirname(__FILE__)) if ENV["RHO_HOME"].nil? rakefilepath = "#{$app_config["sdk"]}/Rakefile" else rakefilepath = "#{ENV["RHO_HOME"]}/Rakefile" end...
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
# 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 = false # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Full error repo...
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'] ||= 'development' # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2....
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 => "apo", :action => "login" # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can a...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module EmailerHelper end
Ruby
module DocumentsHelper end
Ruby
module ApoHelper def delay page.delay(20) do page.visual_effect :fade, 'notice' end end end
Ruby
class Award < ActiveRecord::Base belongs_to :member end
Ruby
class Announcement < ActiveRecord::Base belongs_to :member validates_presence_of :message, :member_id end
Ruby
class Topic < ActiveRecord::Base has_many :threads has_many :posts, :through => :threads validates_presence_of :name end
Ruby
class Event < ActiveRecord::Base belongs_to :mic , :class_name => "Member" has_many :attendance_records has_many :members, :through => :attendance_records validates_presence_of :event_type, :hours, :max_attendees, :name, :date validates_length_of :description, :maximum => 1200 def self.isBefore(first, se...
Ruby
class AttendanceRecord < ActiveRecord::Base belongs_to :member belongs_to :event belongs_to :creator, :class_name => "Member" validates_presence_of :member_id, :event_id end
Ruby
class Position < ActiveRecord::Base belongs_to :member validates_presence_of :position, :member_id def self.getPosition(index) case index #Exec when 0 "President" when 1 "1st VP (Service)" when 2 "2nd VP (Pledge Trainer)" when 3 "3rd VP (Administ...
Ruby
class PledgeClass < ActiveRecord::Base end
Ruby
class Member < ActiveRecord::Base has_many :attendance_records, :conditions => {:waitlist => false} has_many :events, :through => :attendance_records has_many :positions has_many :announcements validates_presence_of :first_name validates_presence_of :last_name validates_presence_of :username validates...
Ruby
class Thread < ActiveRecord::Base belongs_to :topic belongs_to :member belongs_to :author, :class_name => "Member" has_many :posts validates_presence_of :topic_id, :member_id, :subject end
Ruby
class Token < ActiveRecord::Base end
Ruby
class Toggle < ActiveRecord::Base end
Ruby
class Emailer < ActionMailer::Base def password(password, email, name) @recipients = email @from = "APO Website <internet@apouiuc.com>" @subject = "Your password was reset" @sent_on = Time.now @body["message"] = "Hi #{name}, your new password is #{password} \nBe sure to chan...
Ruby
class Post < ActiveRecord::Base belongs_to :member belongs_to :author, :class_name => "Member" belongs_to :thread belongs_to :topic validates_presence_of :topic_id, :member_id, :thread_id, :body end
Ruby
class Document < ActiveRecord::Base def self.save(upload) name = Document.sanitize_filename(upload['title']) filetype = upload['datafile'].original_filename filetype = filetype.split(".") filetype = filetype[filetype.length-1] if upload['date'][5] == " " and upload['date'][...
Ruby
class ApoController < ApplicationController #caches_page :home def login if request.post? @member = Member.authenticate(params[:username], params[:password]) if @member.nil? flash[:warning] = "Invalid username or password" redirect_to :action => "login" elsif @memb...
Ruby
class PositionsController < ApplicationController def create @position = Position.new render :action => "edit" end def edit @position = Position.find(params[:id]) end def save if params[:id].nil? @position = Position.new else @position = Position.find(params[:id]) end ...
Ruby
class DocumentsController < ApplicationController require 'rubygems' def uploadFile Document.save(params[:upload]) redirect_to :action => :done end def download send_file "#{RAILS_ROOT}/Documents/#{params[:file]}", :type => "application/msword", :disposition => "attachment" end def fe...
Ruby
class EventsController < ApplicationController def list if (params[:sort_by] != nil) if (params[:filter] != nil and params[:filter][:type] != "") if params[:filter][:type] == "Dues" @events = Event.find(:all, :select => "events.*", :conditions => ["(events.event_type = \"Dues\" OR events....
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time before_filter :require_login, :except => [:login, :logout, :f...
Ruby
class MembersController < ApplicationController skip_before_filter :verify_authenticity_token #caches_page :list, :show #cache_sweeper :members_sweeper, :only => [:save, :destroy] def list if (params[:sort_by] != nil) if (params[:filter] != nil and params[:filter][:type] != "") filter = par...
Ruby
class EmailerController < ApplicationController def sendmail message = params[:message] recipient = params[:recipient] Emailer.deliver_sent(message, session[:user], recipient) render :inline => "<body bgcolor=#ffd700>Your message has been sent!</body>" end end
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
#!/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/runner'
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/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/profiler'
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/plugin'
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/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/console'
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/process/inspector'
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/reaper'
Ruby