code
stringlengths
1
1.73M
language
stringclasses
1 value
class AddLastFetchedAtToLeagues < ActiveRecord::Migration def self.up add_column :leagues, :last_fetched_at, :datetime end def self.down remove_column :leagues, :last_fetched_at end end
Ruby
class AddIndexes < ActiveRecord::Migration def self.up # bets add_index :bets,:user_id add_index :bets,:match_id add_index :bets,:team_id # leagues add_index :leagues,:sport_id add_index :leagues,:country_id # matches add_index :matches,:home_team_id add_index :matches,:away_...
Ruby
class AddDisplayNameToTeams < ActiveRecord::Migration def self.up add_column :teams,:display_name,:string end def self.down remove_column :teams,:display_name end end
Ruby
class RenamePercentageToWinPercentage < ActiveRecord::Migration def self.up rename_column :users,:percentage,:win_percentage end def self.down rename_column :users,:win_percentage,:percentage end end
Ruby
class CreateMatches < ActiveRecord::Migration def self.up create_table :matches do |t| t.integer :home_team_id t.integer :away_team_id t.string :bet_type t.float :point_spread t.datetime :begin_at t.boolean :result t.float :total_point t.timestamps end end ...
Ruby
class AddTypeToResults < ActiveRecord::Migration def self.up add_column :results,:rtype,:string end def self.down end end
Ruby
class AddWinstreakIdToUsers < ActiveRecord::Migration def self.up add_column :users, :winstreak_id, :integer,:default=>false end def self.down remove_column :users, :winstreak_id end end
Ruby
class CreateIlogActions < ActiveRecord::Migration def self.up create_table :ilog_actions do |t| t.integer :ilog_id t.string :name t.timestamps end add_index :ilog_actions,:ilog_id end def self.down drop_table :ilog_actions end end
Ruby
class AddScoreToUsers < ActiveRecord::Migration def self.up add_column :users, :score, :integer,:default=>0 end def self.down remove_column :users, :score end end
Ruby
class CreateWinstreaks < ActiveRecord::Migration def self.up create_table :winstreaks do |t| t.integer :user_id t.integer :streak_count t.timestamps end end def self.down drop_table :winstreaks end end
Ruby
class AddWinnerIdToMatches < ActiveRecord::Migration def self.up add_column :matches, :winner_id, :integer end def self.down remove_column :matches, :winner_id end end
Ruby
class RemoveFeedUrlAndTypeAndCountryIdFromSports < ActiveRecord::Migration def self.up remove_column :sports,:feed_url remove_column :sports,:country_id remove_column :sports,:type end def self.down add_column :sports,:type,:string add_column :sports,:country_id,:integer add_column :sport...
Ruby
class CreateTeamMappings < ActiveRecord::Migration def self.up create_table :team_mappings do |t| t.string :team_name1 t.string :team_name2 t.timestamps end end def self.down drop_table :team_mappings end end
Ruby
class ChangeIdToBignumFromUsers < ActiveRecord::Migration def self.up change_column :users,:id,:integer,:limit=>11 end def self.down change_column :users,:id,:integer end end
Ruby
class Fetcher def self.logger @@logger ||= Logger.new(File.join(RAILS_ROOT,"log","fetcher.log")) end def logger self.class.logger end def fetch_matches begin puts "start fetch matches" logger.info "#{Time.now} start fetch matches" matches_count = Sport.fetch_matches logg...
Ruby
namespace :counter_cache do desc "update matche counter cache" task :matches=>:environment do Match.all.each do |match| match.bets_count = match.bets.count match.save false end end desc "update user score" task :user_score=>:environment do User.all.each do |user| user.calc_score...
Ruby
namespace :clear do desc "clear all" task :all=>[:leagues,:bets,:sports,:matches,:users,:winstreaks,:prizes,:countries] desc "clear leagues" task :leagues=>:environment do League.destroy_all end desc "clear bets" task :bets=>:environment do Bet.destroy_all end desc "clear countries" task ...
Ruby
require "open-uri" def valid_leagues file = File.join(Rails.root,"config","leagues.yml") yaml = YAML.load_file file yaml && yaml["leagues"] || {} end def league_name_to_id(content,league_name) regexp = %r{<tr><td>(\d+)<\/td><td>(.+?)<\/td><td>\s*#{Regexp.escape(league_name)}\s*<\/td><\/tr>}i if content =~ re...
Ruby
namespace :data do desc "导入默认数据" task :load=>:environment do [ # basketball {:type=>"Basketball",:country=>"America",:name=>"NBA",:feed_url=>"url"}, # football # England {:type=>"Football",:country=>"England",:name=>"Premier League"}, {:type=>"Football",:country=>"Engl...
Ruby
require "open-uri" require "timeout" =begin 20 * * * * * cd /home/jill/13wins && GEM_PATH=/opt/local/lib/ruby/gems:/opt/local/lib/ruby/gems/bin /opt/local/bin/rake RAILS_ENV=production win:fetch > /home/jill/13wins/log/cron_fetch.log 2>&1 =end namespace :win do desc 'UPDATE ' RAILS_ENV='production' ...
Ruby
namespace :generate do task :ensure_user_selected_prize=>:environment do prize = Prize.first User.all.each do |user| unless user.prize user.prize = prize user.save end end end task :result=>:environment do match = Match.next_match if match puts "current matc...
Ruby
module Facebooker::Rails::DelayedUserAction def self.included(base) base.class_eval do alias_method_chain :send_message,:delayed end end def delayed(*args) if args.empty? @delayed else @delayed = args.first end end def send_message_with_delayed(message) @recipients...
Ruby
#!/usr/bin/ruby1.8 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...
Ruby
#!/usr/bin/ruby1.8 # # 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 #...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' require "flexmock/test_unit" class Test::Unit::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This en...
Ruby
#!/usr/bin/ruby #=============================================================================== # # FILE: siab.rb # # USAGE: ruby siab.rb [start|stop|restar|help] # # DESCRIPTION: a ShellInAbox control script and configuration system reader. # To auto-configure a shellinabox service creat...
Ruby
Reported by bXXX.rXXX@oXXX.com, Mar 11, 2011 I found the need to have a nice start / stop / restart wrapper for shellinabox, and a quick way to add new configurations and URLS. Attached is a file that does just that. It is ruby based, and expects a conf directory in the shellinthebox home directory. All file(s) plac...
Ruby
#! /usr/bin/ruby require 'fileutils' require './lib/maruku.rb' require 'date' def growl(message) unless File.exist?("/usr/local/bin/growlnotify") puts "growlnotify is not installed in /usr/local/bin/; you can install it from the Growl DMG." puts "message: #{message}" return end %x(/usr/local/bi...
Ruby
#! /usr/bin/ruby require 'fileutils' require './lib/maruku.rb' require 'date' def growl(message) unless File.exist?("/usr/local/bin/growlnotify") puts "growlnotify is not installed in /usr/local/bin/; you can install it from the Growl DMG." puts "message: #{message}" return end %x(/usr/local/bi...
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
class CreateCustomerTags < ActiveRecord::Migration def change create_table :customer_tags do |t| t.integer :customer_id, :tag_id, :enterprise_id t.timestamps end end end
Ruby
class CreateContactWays < ActiveRecord::Migration def change create_table :contact_ways do |t| t.integer :customer_id, :enterprise_id t.string :way, :type_name, :type t.timestamps end end end
Ruby
class AddPositionToGroupsAndUsers < ActiveRecord::Migration def change change_table :groups do |t| t.integer :position, :default => 0 end change_table :users do |t| t.integer :position, :default => 0 end end end
Ruby
class CreateCustomers < ActiveRecord::Migration def change create_table :customers do |t| t.integer :enterprise_id t.string :first_name, :last_name t.string :sex, :default => 'unknown' t.string :title, :organization t.text :background_info t.integer :created_by_id, :updated_by_id ...
Ruby
class CreateEnterprises < ActiveRecord::Migration def self.up create_table :enterprises do |t| t.string :name, :address, :email, :link_phone, :fax, :qq t.text :synopsis t.integer :admin_id t.timestamps end end def self.down drop_table :...
Ruby
class CreateGroups < ActiveRecord::Migration def self.up create_table :groups do |t| t.integer :enterprise_id t.string :name t.text :remark t.timestamps end create_table :groups_users, :id => false do |t| t.integer :group_id t.integer :user_id end end def self....
Ruby
class CreateProjects < ActiveRecord::Migration def change create_table :projects do |t| t.integer :enterprise_id t.string :name, :address t.text :synopsis, :remark t.timestamps end end end
Ruby
class CreateCustomerVisibleToUsers < ActiveRecord::Migration def change create_table :customer_visible_to_users do |t| t.integer :customer_id, :user_id, :enterprise_id t.timestamps end end end
Ruby
class CreateTasks < ActiveRecord::Migration def self.up create_table :tasks do |t| t.string :name t.integer :enterprise_id, :executor_id, :initiator_id, :customer_id, :feed_id t.string :visible_scope, :default => 'only_myself' t.string :type_name, :default =...
Ruby
class CreateBrowsedRecords < ActiveRecord::Migration def change create_table :browsed_records do |t| t.integer :customer_id, :user_id, :enterprise_id t.timestamp :browsed_at t.timestamps end end end
Ruby
class CreateImages < ActiveRecord::Migration def change create_table :images do |t| t.integer :user_id t.string :file_file_name, :file_content_type t.integer :file_file_size t.timestamp :file_updated_at t.timestamps end end end
Ruby
class CreateCustomerVisibleToGroups < ActiveRecord::Migration def change create_table :customer_visible_to_groups do |t| t.integer :customer_id, :group_id, :enterprise_id t.timestamps end end end
Ruby
class CreateContactRecords < ActiveRecord::Migration def change create_table :contact_records do |t| t.integer :customer_id, :enterprise_id t.text :content t.date :contacted_on t.integer :recorded_by_id t.timestamps end end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :full_name t.string :sex, :default => 'unknown' t.string :email, :mobile, :address, :password_digest, :pk, :login_token t.integer :enterprise_id t.strin...
Ruby
class CreateTags < ActiveRecord::Migration def change create_table :tags do |t| t.string :name, :ping_yin t.integer :enterprise_id t.timestamps end end end
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
#!/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__) Ed88::Application.load_tasks
Ruby
source 'http://ruby.taobao.org' gem 'rails', '3.2.3' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' gem 'json','1.6.5' gem 'hz2py' gem 'paperclip','2.4.5' gem 'cocaine' gem 'rails3-jquery-autocomplete', '1.0.4' gem 'spreadsheet' gem 'excel_rails' grou...
Ruby
module ApplicationHelper #被访问: :browser_version def accessed_by?(args = {}) request.env['HTTP_USER_AGENT'].downcase.index(args[:browser_version]) end # qtip args :content :tip :target :tooltip def qtip(jquery_selector,args = {}) raw "$('#{jquery_selector}').qtip({ content: '#{args[:content]...
Ruby
module FeedsHelper end
Ruby
module CustomersHelper def options_of_phones_type_names [['办公','办公'],['传真','传真'],['手机','手机'],['家庭','家庭'],['其他','其他']] end def options_of_emails_address_type_names [['办公','办公'],['个人','个人'],['其他','其他']] end def options_of_web_sites_type_names [['公司','公司'],['单位','单位'],['个人','个人'],['微博','微博']...
Ruby
module UsersHelper def has_logined? current_user_id end def has_logined_by?(user_or_id) user_or_id.try(:id) == current_user_id || user_or_id == current_user_id end def current_enterprise current_user.try(:enterprise) end def current_user User.find(current_user_id) if current_user_id ...
Ruby
module TasksHelper def task_type_class_name(type_name) @task_type_class_name ||= {} @task_type_class_name[type_name] ||= "type_#{@task_type_class_name.keys.size}" end def task_types raw "<option value='提醒' style='font-weight:bold;'>--请选择--</option> <option value='提醒'>提醒</option> <o...
Ruby
module ProjectsHelper end
Ruby
module EnterprisesHelper end
Ruby
module PasswordsHelper end
Ruby
module AdminsHelper end
Ruby
module GroupsHelper end
Ruby
class ContactWay::WebSite < ContactWay end
Ruby
class ContactWay::Phone < ContactWay end
Ruby
class ContactWay::Im < ContactWay end
Ruby
class ContactWay::Email < ContactWay end
Ruby
class ContactWay::Address < ContactWay end
Ruby
class ContactRecord < ActiveRecord::Base attr_protected [] belongs_to :customer belongs_to :recorded_by, :class_name => "User", :foreign_key => "recorded_by_id" validates :customer_id, :content, :contacted_on, :recorded_by_id, :presence => true default_scope lambda { where( :enterp...
Ruby
class Enterprise < ActiveRecord::Base attr_protected [] validates :name, :presence => true, :uniqueness => true attr_protected [] belongs_to :admin, :class_name => "User", :foreign_key => "admin_id" has_many :users has_many :groups before_save do |enterprise| enterprise.qq ...
Ruby
class BrowsedRecord < ActiveRecord::Base attr_protected [] belongs_to :project belongs_to :building belongs_to :customer belongs_to :user belongs_to :enterprise validates :user_id, :enterprise_id, :presence => true default_scope lambda { where( :enterprise_id => Enterprise.current_id, ...
Ruby
class CustomerVisibleToUser < ActiveRecord::Base attr_protected [] belongs_to :customer belongs_to :user validates :customer_id, :uniqueness => { :scope => :user_id } default_scope lambda { where( :enterprise_id => Enterprise.current_id ) } end
Ruby
class Tag < ActiveRecord::Base attr_protected [] belongs_to :enterprise has_many :customer_tags validates :name, :enterprise_id, :presence => true validates :name, :uniqueness => { :scope => :enterprise_id } default_scope lambda { where( :enterprise_id => Enterprise.current_id ...
Ruby
class CustomerTag < ActiveRecord::Base attr_protected [] belongs_to :customer belongs_to :tag belongs_to :enterprise validates :customer_id, :tag_id, :enterprise_id, :presence => true validates :customer_id, :uniqueness => { :scope => [ :enterprise_id, :tag_id ...
Ruby
class User < ActiveRecord::Base include ActiveModel::Validations class UniquenessEnterpriseValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) record.errors[attribute] << "已注册" if value.nil? end end has_secure_password validates :enterprise_id, :uniquene...
Ruby
class CustomerVisibleToGroup < ActiveRecord::Base attr_protected [] belongs_to :customer belongs_to :group validates :customer_id, :uniqueness => { :scope => :group_id } default_scope lambda { where( :enterprise_id => Enterprise.current_id ) } end
Ruby
class ContactWay < ActiveRecord::Base attr_protected [] belongs_to :customer validates :way, :type_name, :presence => true default_scope lambda { where( :enterprise_id => Enterprise.current_id ) } end
Ruby
class Project < ActiveRecord::Base attr_protected [] belongs_to :enterprise validates :name, :address, :enterprise_id, :presence => true end
Ruby
class Image < ActiveRecord::Base attr_protected [] belongs_to :user_id has_attached_file :file, :styles => { :large => "800x800>", :normal => "300x300>", :small => '64x64>' }, :hash_data => ':id/:style/:updated_at/:basename.:extension', :hash_secret => "longSecretString", ...
Ruby
class Customer < ActiveRecord::Base attr_protected [] belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_id' belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_id' has_many :phones, :class_name => "ContactWay::Phone", :foreign_key => "customer_id", :order => 'id a...
Ruby
class Task < ActiveRecord::Base attr_protected [] validates :name, :type_name, :initiator_id, :executor_id, :due_on, :status, :presence => true belongs_to :feed belongs_to :customer belongs_to :initiator,:class_name => 'User',:foreign_key => 'initiator_id' belongs_to :executor...
Ruby
class Group < ActiveRecord::Base attr_protected [] attr_protected [] has_and_belongs_to_many :users, :uniq => true belongs_to :enterprise validates :enterprise_id, :presence => true validates :name, :presence => true validates :name, :uniqueness => { :scope => :enterprise_id } default_scope l...
Ruby
class PasswordsController < ApplicationController def edit @user = User.current end def update @user = User.current if @user.update_attributes params[:user] flash[:success] = '• 已成功修改,请妥善保管密码!' redirect_to current_user_url(@user.id) else render :edit end end end
Ruby
class ApplicationController < ActionController::Base protect_from_forgery before_filter :error_message_follows_field, :current_user_id, :authorize, :relogin_check def must_be_admin if not current_user.is_admin? redirect_to :back end end # 必须是同事 def must_be_colleague if curre...
Ruby
class ProjectsController < ApplicationController def index @projects = params[:enterprise_id].blank? ? Project.all : Project.where(:enterprise_id => params[:enterprise_id]) end def show @project = Project.find(params[:id]) end def new @project = Project.new end def create @project = Pr...
Ruby
class EnterprisesController < ApplicationController before_filter :must_be_admin, :except => :show def show @enterprise = Enterprise.current end def edit @enterprise = Enterprise.current end def update @enterprise = Enterprise.current if @enterprise.update_attributes(params[:enterprise...
Ruby
class TasksController < ApplicationController def index @task = Task.new end def create @task = Task.new(params[:task]) @task.save ? redirect_to(tasks_url) : render(:index ) end def edit @task = Task.find(params[:id]) params[:type] = "waiting" if not params[:type].present? end ...
Ruby
class UsersController < ApplicationController before_filter :must_be_admin, :except => [:index,:current, :show,:edit_current,:update_current] before_filter :must_be_colleague, :only => [:edit,:update,:edit_current,:update_current,:reset_password, :lock, :active, :disable] def index params[:group_id] ||...
Ruby
class AdminsController < ApplicationController before_filter :authorize,:relogin_check, :except => [:new, :create] def new @user = User.new end def create if params[:user][:enterprise_id].present? @enterprise = Enterprise.find(params[:user][:enterprise_id]) @enterprise.update_attributes :...
Ruby
class TagsController < ApplicationController def new end def create if params[:tags][:name].blank? render :new else @tag_names = instance_eval("%w(#{params[:tags][:name]})") @customers = Customer.find(params[:customer_id]) @first = @customers.first @tags = @tag_names...
Ruby
class GroupsController < ApplicationController before_filter :must_be_admin, :except => [:index] def index @groups = Group.all end def new @group = Group.new end def create @group = Group.new(params[:group]) if @group.save flash[:success] = "• 『#{@group.name}』组的基本资料保存成功!" red...
Ruby
class FeedsController < ApplicationController def index end end
Ruby
class SessionsController < ApplicationController def authorize end def relogin_check end def close_browser_remind session[:close_browser_remind] = true render :status => 200, :text => 'success' end def new @http_referer = params[:http_referer].present? ? params[:http_referer] ...
Ruby
class CustomersController < ApplicationController def autocomplete_by_key_words @customers = Customer.where(['key_words like ? ', "%#{params[:term]}%"]).active end def index if params[:tag_id].present? begin @tag = Tag.find(params[:tag_id]) @customers = Customer.by_tag_id(params[:t...
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): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', ...
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
# 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. # 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. # 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. Ed88::Application.config.session_store :cookie_store, :key => '_ed88_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 gene...
Ruby
Ed88::Application.routes.draw do # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match 'products/:id' => 'catalog#view' # Keep in mind you can assign values other than :controller and :action # Sample of named route: # match 'products...
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
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Ed88::Application.initialize! #require 'openssl' #OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
Ruby
Ed88::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_co...
Ruby