code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/usr/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.log # an...
Ruby
#!/usr/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 impaired re...
Ruby
#!/usr/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 impaired re...
Ruby
#!/usr/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.log # an...
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
# 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 web 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 ...
Ruby
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb unless defined?(RAILS_ROOT) root_path = File.join(File.dirname(__FILE__), '..') unless RUBY_PLATFORM =~ /(:?mswin|mingw)/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).realpath.to...
Ruby
ActionController::Routing::Routes.draw do |map| # 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 assign values other than :controller and :action # ...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper include CalendarHelper def logged_in? current_user != :false end def current_user @current_user ||= (session[:user] && User.find_by_id(session[:user])) || :false end def is_admin? re...
Ruby
require 'date' # CalendarHelper allows you to draw a databound calendar with fine-grained CSS formatting module CalendarHelper VERSION = '0.2.2' # Returns an HTML calendar. In its simplest form, this method generates a plain # calendar (which can then be customized using CSS) for a given month and year. # Ho...
Ruby
module EventHelper end
Ruby
module CourseHelper end
Ruby
module AccountHelper end
Ruby
class UserNotifier < ActionMailer::Base def signup_notification(user) setup_email(user) @subject += ' Activa tu cuenta.' body( :user => user, :url => url_for(:host => StringSetting.find_by_name("site-host").value, :controller => :account, :action => :activate, :id => user.activation_code)) end...
Ruby
class AssignmentAnswer < ActiveRecord::Base belongs_to :assignment belongs_to :grader, :class_name => "User", :foreign_key => "grader_id" belongs_to :user has_one :answer_blob, :dependent => :destroy validates_numericality_of :grade, :message => 'La calificación debe ser un numero entre 0 y 100', :if => Proc...
Ruby
class Event < ActiveRecord::Base belongs_to :course belongs_to :user has_one :event_blob, :dependent => :destroy validates_presence_of :course, :message => 'No hay curso asociado.' validates_presence_of :name, :message => 'El evento debe tener un nombre.' validates_presence_of :due_date, :message => 'El ev...
Ruby
class EventBlob < ActiveRecord::Base belongs_to :event belongs_to :assignment, :class_name => 'Assignment', :foreign_key => 'event_id' validates_presence_of :data, :message => 'Debes contestar con alg&uacute;n dato.' def data=(param) if param.is_a?(StringIO) or param.is_a?(Tempfile) self[:file_name]...
Ruby
class Assignment < Event belongs_to :user belongs_to :course has_many :assignment_answers, :dependent => :destroy has_one :event_blob, :foreign_key => 'event_id', :dependent => :destroy validates_presence_of :name, :message => 'La asignación debe tener un nombre.' validates_presence_of :course, :message =>...
Ruby
class SystemSetting < ActiveRecord::Base end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base has_one :profile, :dependent => :destroy has_many :created_courses, :class_name => "Course" has_and_belongs_to_many :courses # Usar polimorfismo sigue siendo una chinga en Rails 1.2 (espero que en Rails # 2.0 esto mejore). Es más fácil si separamos eventos...
Ruby
class StringSetting < SystemSetting end
Ruby
class Profile < ActiveRecord::Base belongs_to :user validates_format_of :telephone, :with => /^\d+(-|\d)*$/, :message => 'El tel&eacute;fono s&oacute;lo puede tener d&iacute;gitos y guiones.', :if => Proc.new {|profile| not profile.telephone.nil? and profile.telephone != '' and profile.telephone.length > 0...
Ruby
class AnswerBlob < ActiveRecord::Base belongs_to :assignment_answer validates_presence_of :data, :message => 'La respuesta no puede estar vacía.' def data=(param) if param.is_a?(StringIO) or param.is_a?(Tempfile) self[:file_name] = param.original_filename.gsub(/^.*(\\|\/)/, '') self[:data] = par...
Ruby
class Course < ActiveRecord::Base belongs_to :creator, :class_name => "User", :foreign_key => "user_id" has_and_belongs_to_many :users has_many :events, :conditions => "type IS NULL OR type = ''", :dependent => :destroy, :order => "due_date DESC" has_many :assignments, :dependent => :destroy validates_presen...
Ruby
class IntegerSetting < SystemSetting def value read_attribute(:value).to_i end def value=(val) write_attribute(:value, val.to_s) end end
Ruby
class CourseController < ApplicationController before_filter :login_required, :only => [ :show, :enroll, :add_event, :list_own, :index, :list, :quit ] before_filter :admin_required, :only => [ :create, :new, :destroy, :enroll_list_student, :enroll_list_instructor ] before_filter :instructor_required, :only => [ :...
Ruby
class EventController < ApplicationController before_filter :login_required, :except => [:add_assignment, :rate_answer] before_filter :instructor_required, :only => [:add_assignment, :rate_answer] # Muestra los eventos que uno a creado o todos los eventos si eres # administrador. def list_own if not s...
Ruby
class SettingController < ApplicationController #Solo puede ser accesados por el administrador before_filter :admin_required #Muestra todos los parametros configurables por el administrador def index list render :action=>'list' end # Lista todas las opciones del sistema. def list @title = "O...
Ruby
class AccountController < ApplicationController # If you want "remember me" functionality, add this before_filter to Application Controller #before_filter :login_from_cookie # Los siguientes requieren un usuario logeado (cualquiera) before_filter :login_required, :only => [:index, :list, :edit, :view, :logout,...
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 # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_contenid-o...
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/breakpointer'
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/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/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/breakpointer'
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
#!/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/destroy'
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/server'
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/plugin'
Ruby
class CreateGlobalCourse < ActiveRecord::Migration def self.up u = User.new(:login => 'global_events', :password => 'globBal_eVent_', :password_confirmation => 'globBal_eVent_', :email => 'changeme@example.com', :kind => 'Instructor') u.save! p = Profile.new(:real_name => 'Este usuario puede editar los ev...
Ruby
class AddUserActivation < ActiveRecord::Migration def self.up add_column :users, :activation_code, :string end def self.down remove_column :users, :activation_code end end
Ruby
class OopsForgotToAddEndDateToCourse < ActiveRecord::Migration def self.up add_column :courses, :end_date, :datetime end def self.down remove_column :courses, :end_date end end
Ruby
class GenerateConfigurations < ActiveRecord::Migration def self.up create_table :system_settings do |t| t.column :name, :string, :null => false t.column :description, :text t.column :value, :text, :null => false t.column :type, :string end StringSetting.create( :name => "admin-mai...
Ruby
class AddUsersStylesheetColumn < ActiveRecord::Migration def self.up add_column :users, :stylesheet, :string User.find(:all).each { |u| u.stylesheet = 'principalEs.css' u.save! } end def self.down remove_column :users, :stylesheet end end
Ruby
class EventDurationToExpireDate < ActiveRecord::Migration def self.up add_column :events, :expire_date, :datetime, :null => false Event.find(:all).each { |event| event.expire_date = event.due_date + event.duration.tv_secs } remove_column :events, :duration end def self.down add_column :events, :d...
Ruby
#Motivación: El pinche ActiveRecord hace un "select * from blahblah" cada vez #que le pides datos sobre algun evento / respuesta a una tarea. Esto significa #que lee todo el blob, así sea de 16Megas incluso si no lo vas a usar. Hay dos #soluciones que se me ocurren: # *usar :select => ... en las opciones de find - se p...
Ruby
#Esta migración crea el usuario 'root' con un password default ('rootroot') class CreateUsers < ActiveRecord::Migration def self.up root = User.create( :login => 'root', :password => 'rootroot', :email => 'root@localhost.localdomain', :password_confirmation =>...
Ruby
module AuthenticatedSystem protected # Returns true or false if the user is logged in. # Preloads @current_user with the user model if they're logged in. def logged_in? current_user != :false end # Accesses the current user from the session. def current_user @current_user ||= (ses...
Ruby
desc 'Create YAML test fixtures from data in an existing database. Defaults to development database. Set RAILS_ENV to override.' task :extract_fixtures => :environment do sql = "SELECT * FROM %s" skip_tables = ["schema_info" ] ActiveRecord::Base.establish_connection (ActiveRecord::Base.connection.tables - skip...
Ruby
module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user] = user ? users(user).id : nil end def content_type(type) @request.env['Content-Type'] = type end def accept(accept) @request.env["HTTP_ACCEPT"] = accept en...
Ruby
#!/usr/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 impaired re...
Ruby
#!/usr/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 impaired re...
Ruby
#!/usr/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.log # an...
Ruby
#!/usr/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 impaired re...
Ruby
#!/usr/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 impaired re...
Ruby
#!/usr/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.log # an...
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
# 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' }]) # Major.create(:name...
Ruby
class CreateHomes < ActiveRecord::Migration def self.up create_table :homes do |t| t.string :title t.timestamps end end def self.down drop_table :homes end end
Ruby
class AddActionPointToUser < ActiveRecord::Migration def self.up add_column :users, :action_id, :integer add_column :users, :points, :bigint remove_column :users, :activity_id end def self.down add_column :users, :activity_id remove_column :users, :action_id remove_column :user...
Ruby
class DeleteActivityTables < ActiveRecord::Migration def self.up drop_table :activity end def self.down end end
Ruby
class AddActivityColumns2 < ActiveRecord::Migration def self.up add_column :activity, :change, :string add_column :activity, :action, :string remove_column :activity, :contact_id remove_column :activity, :company_id end def self.down remove_column :activity, :change, :string re...
Ruby
class CreateActions < ActiveRecord::Migration def self.up create_table :actions do |t| t.timestamp :created_at t.bigint :points t.string :entity_changed t.string :action t.int :user_id t.timestamps end end def self.down drop_table :actions end end
Ruby
class AddPtsAction < ActiveRecord::Migration def self.up add_column :actions, :points, :bigint end def self.down remove_column :actions, :points end end
Ruby
class Usertoaction < ActiveRecord::Migration def self.up add_column :actions, :user_id, :int end def self.down remove_column :actions, :user_id end end
Ruby
class UserSession < ActiveRecord::Migration def self.up create_table :user_session do |t| t.column :username, :string t.column :password, :string end end def self.down drop_table :user_session end end
Ruby
class DeleteActivity < ActiveRecord::Migration def self.up end def self.down end end
Ruby
class CreateContacts < ActiveRecord::Migration def self.up create_table :contacts do |t| t.string :title t.string :name t.int :company_id t.string :city t.string :state t.string :country t.date :date_updated t.string :linkedin_id t.int :industry_id t.dat...
Ruby
class AddActivityColumns < ActiveRecord::Migration def self.up create_table :activity do |t| t.column :created_at, :timestamp t.column :points, :bigint t.column :contact_id, :string t.column :company_id, :string end end def self.down end end
Ruby
class CreateCompanies < ActiveRecord::Migration def self.up create_table :companies do |t| t.string :company_site t.string :company_name t.string :company_postcode t.string :company_address t.string :company_state t.date :company_date_updated t.string :linkedin_id t...
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :screen_name t.string :first_name t.string :last_name t.string :profession t.string :email t.string :crypted_password t.string :password_salt t.string :persistence_token ...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class ActiveSupport::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 da...
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/destroy'
Ruby