code
stringlengths
1
1.73M
language
stringclasses
1 value
# == Schema Information # Schema version: 38 # # Table name: event_comments # # id :integer(11) not null, primary key # event_id :integer(11) # user_id :integer(11) # title :string(255) # content :text # content_html :text # created_at :datetime # updated_at :datetime # c...
Ruby
# == Schema Information # Schema version: 38 # # Table name: event_pics # # id :integer(11) not null, primary key # parent_id :integer(11) # content_type :string(255) # filename :string(255) # thumbnail :string(255) # size :integer(11) # width :integer(11) # height :...
Ruby
# == Schema Information # Schema version: 38 # # Table name: photos # # id :integer(11) not null, primary key # parent_id :integer(11) # content_type :string(255) # filename :string(255) # thumbnail :string(255) # size :integer(11) # width :integ...
Ruby
# == Schema Information # Schema version: 38 # # Table name: students # # id :integer(11) not null, primary key # user_id :integer(11) # school_id :integer(11) # last_name :string(255) # first_name :string(255) # gender :integer(11) # birth ...
Ruby
# == Schema Information # Schema version: 38 # # Table name: books # # id :integer(11) not null, primary key # user_id :integer(11) # title :string(255) # subtitle :string(255) # author :string(255) # isbn :string(255) # publisher :string...
Ruby
class UserMailer < ActionMailer::Base def signup_notification(user) setup_email(user) @subject += '激活你的多背一公斤(1KG.org)帐户' if ENV['RAILS_ENV'] == 'development' @body[:url] = "http://localhost:3000/activate/#{user.activation_code}" else @body[:url] = "http://www.1kg.org/activate/#{user.a...
Ruby
# == Schema Information # Schema version: 38 # # Table name: events # # id :integer(11) not null, primary key # title :string(255) # category :integer(11) # start_at :datetime # end_at :datetime # location :string(255) # content :text # content_html :text # school_id...
Ruby
class UserObserver < ActiveRecord::Observer def after_create(user) UserMailer.deliver_signup_notification(user) end def after_save(user) UserMailer.deliver_activation(user) if user.recently_activated? end end
Ruby
# == Schema Information # Schema version: 38 # # Table name: book_covers # # id :integer(11) not null, primary key # parent_id :integer(11) # content_type :string(255) # filename :string(255) # thumbnail :string(255) # size :integer(11) # width :integer(11) # height ...
Ruby
# == Schema Information # Schema version: 38 # # Table name: posts # # id :integer(11) not null, primary key # topic_id :integer(11) # user_id :integer(11) # content :text # content_html :text # created_at :datetime # updated_at :datetime # class Post < ActiveRecord::Base belon...
Ruby
# == Schema Information # Schema version: 38 # # Table name: schools # # id :integer(11) not null, primary key # area_id :integer(11) # submitor_id :integer(11) # info_source :string(255) # is_validate :boolean(1) # is_hidden :boolean(1) # create...
Ruby
# == Schema Information # Schema version: 38 # # Table name: relationships # # id :integer(11) not null, primary key # user_id :integer(11) # neighbor_id :integer(11) # created_at :datetime # class Relationship < ActiveRecord::Base belongs_to :user, :class_name => "User", :foreign_key => "user_...
Ruby
# == Schema Information # Schema version: 38 # # Table name: moderatorships # # id :integer(11) not null, primary key # group_id :integer(11) # user_id :integer(11) # created_at :datetime # class Moderatorship < ActiveRecord::Base belongs_to :user belongs_to :group before_create { |r| count(...
Ruby
# == Schema Information # Schema version: 38 # # Table name: school_comments # # id :integer(11) not null, primary key # user_id :integer(11) # school_id :integer(11) # include_update :boolean(1) # title :string(255) # content :text # content_html :text # created_at...
Ruby
# == Schema Information # Schema version: 38 # # Table name: participations # # id :integer(11) not null, primary key # user_id :integer(11) # event_id :integer(11) # rank :integer(11) # created_at :datetime # class Participation < ActiveRecord::Base belongs_to :event belongs_to :user ...
Ruby
# == Schema Information # Schema version: 38 # # Table name: users # # id :integer(11) not null, primary key # login :string(255) # email :string(255) # crypted_password :string(40) # salt :string(40) # created_at ...
Ruby
class Mailer < ActionMailer::Base def test(user, msg) @subject = 'Mailer#test' @body = {:user => user, :message => msg} @recipients = user.email @from = ActionMailer::Base.smtp_settings[:user_name] @sent_on = Time.now @headers = {} end def message_notification(mess...
Ruby
# == Schema Information # Schema version: 38 # # Table name: areas # # id :integer(11) not null, primary key # parent_id :integer(11) # lft :integer(11) # rgt :integer(11) # title :string(255) # zipcode :integer(11) # class Area < ActiveRecord::Base acts_as_nested_set has_many...
Ruby
# == Schema Information # Schema version: 38 # # Table name: messages # # id :integer(11) not null, primary key # sender_id :integer(11) # receiver_id :integer(11) # title :string(255) # content :text # content_html :text # created_at :datetime # unread :boolean(1) def...
Ruby
# == Schema Information # Schema version: 38 # # Table name: photo_comments # # id :integer(11) not null, primary key # user_id :integer(11) # photo_id :integer(11) # title :string(255) # content :text # content_html :text # created_at :datetime # updated_at :datetime # c...
Ruby
class RelationshipObserver < ActiveRecord::Observer def after_create(relationship) msg = Message.new msg.sender_id = 0 msg.receiver = relationship.neighbor msg.title = "#{relationship.user.login}刚刚加你为好友了" msg.content = "#{relationship.neighbor.login},\r\n\r\n" + "#{relationship....
Ruby
# == Schema Information # Schema version: 38 # # Table name: visiteds # # id :integer(11) not null, primary key # user_id :integer(11) # school_id :integer(11) # visit_at :date # created_at :datetime # class Visited < ActiveRecord::Base belongs_to :traveler, :class_name => "User", :foreign_key...
Ruby
class Searcher end
Ruby
# == Schema Information # Schema version: 38 # # Table name: groups # # id :integer(11) not null, primary key # creator_id :integer(11) # title :string(255) # content :text # content_html :text # created_at :datetime # updated_at :datetime # class Group < ActiveRecord::Base val...
Ruby
# == Schema Information # Schema version: 38 # # Table name: topics # # id :integer(11) not null, primary key # group_id :integer(11) # user_id :integer(11) # title :string(255) # content :text # content_html :text # sticky :boolean(1) # created_at :datetime # updated...
Ruby
class BooksController < ApplicationController before_filter :login_required, :except => [:show] before_filter :unread_messages_amount, :only => [:new, :edit, :show] include BooksHelper def new @book = Book.new end def create @book = Book.new(params[:book]) @book.user = current_user ...
Ruby
class EventsController < ApplicationController before_filter :set_nav_session before_filter :login_required, :except => [:index, :show, :all, :category] before_filter :unread_messages_amount, :only => [:index, :all, :category, :show, :new, :edit, :new_pic, :choi...
Ruby
class MessagesController < ApplicationController before_filter :login_required, :set_nav_session before_filter :unread_messages_amount, :only => [:index, :outbox, :new, :show, :reply] # Inbox def index @messages = Message.paginate(:all, :page => params[:page] || 1, :condi...
Ruby
class SearchersController < ApplicationController # 只允许登录用户搜索 before_filter :login_required # 常规sql查询来搜索 def search query = params[:keywords] @keywords = query unless query.blank? if !query.to_s.strip.empty? tokens = query.split.collect {|c| "%#{c.downcase}%"} @schools = Scho...
Ruby
class AreasController < ApplicationController # for xhr, return areas list def list list_result end def list_for_user list_result end def list_for_admin list_result end def new @area = Area.new() # pass pid to view, and use in create method @parent_id = params[:pid] ...
Ruby
class PostsController < ApplicationController before_filter :login_required before_filter :unread_messages_amount, :only => [:edit] def create @group = Group.find(params[:group_id]) @topic = Topic.find(params[:topic_id]) post = Post.new(params[:post]) post.user = current_user @topic.posts <...
Ruby
class PhotoCommentsController < ApplicationController before_filter :login_required before_filter :unread_messages_amount, :only => [:edit] def create @photo = Photo.find(params[:photo_id]) @comment = PhotoComment.new(params[:comment]) @comment.photo = @photo @comment.user = current_user @c...
Ruby
class Admin::GeneralController < Admin::BaseController before_filter :unread_messages_amount, :only => [:index, :edit_school_moderator, :school_trash_bin, :school_archives, :school_manage, :area_manage] def inde...
Ruby
class Admin::BaseController < ApplicationController before_filter :login_required, :set_nav_session protected def login_required authorized? ||access_denied end def authorized? logged_in? && current_user.is_admin != :false end def set_nav_session session[:nav] = "" end end
Ruby
class StudentsController < ApplicationController before_filter :login_required before_filter :unread_messages_amount, :only => [:new, :edit, :show] def new redirect_to schools_url unless params[:school_id] @school = School.find(params[:school_id]) @student = Student.new(:school_id => params[:schoo...
Ruby
class TopicsController < ApplicationController before_filter :login_required, :except => [:show] before_filter :unread_messages_amount, :only => [:new, :edit, :show] def new @group = Group.find(params[:group_id]) @topic = Topic.new end def create @group = Group.find(params[:group_id]) ...
Ruby
class IntroController < ApplicationController before_filter :unread_messages_amount def index session[:nav] = "index" #@tags = School.tag_counts.sort{|a,b| b.count <=> a.count}.slice(0,50).sort_by{rand} @participations = Participation.recent_join @visits = Visited.all @latest_events = ...
Ruby
class UsersController < ApplicationController before_filter :set_nav_session before_filter :login_required, :except => [:new, :create, :show, :confirmed_schools, :unconfirmed_schools, :neighbors, :published_events, :activate...
Ruby
class SchoolCommentsController < ApplicationController before_filter :login_required before_filter :unread_messages_amount, :only => [:edit] def create @school = School.find(params[:school_id]) @comment = SchoolComment.new(params[:comment]) @comment.school = @school @comment.user = current_user...
Ruby
class PhotosController < ApplicationController before_filter :login_required, :except => [:index, :show] before_filter :unread_messages_amount, :only => [:index, :new, :medit, :edit, :show, :share_event, :share_school] def index session[:nav] = "photos" ...
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 => '_1kg.org_se...
Ruby
class Dizhen::EventsController < Dizhen::BaseController before_filter :unread_messages_amount def index build_events(["events.end_at > now() and events.ref='dizhen.1kg.org'"]) end def all build_events(["events.ref='dizhen.1kg.org'"]) end def category build_events(["events.category=? and...
Ruby
class Dizhen::GeneralController < Dizhen::BaseController before_filter :unread_messages_amount def index end def donate end end
Ruby
class Dizhen::BaseController < ApplicationController before_filter :set_nav_session private def set_nav_session session[:nav] = "dizhen" end end
Ruby
class Dizhen::SchoolsController < Dizhen::BaseController before_filter :login_required, :except => [:index, :area, :comments, :photos] before_filter :unread_messages_amount def index @schools = School.find(:all, :conditions => "info_source='dizhen.1kg.org' and is_hidden!=1", :select => "id, area_id") @...
Ruby
class Dizhen::GroupsController < Dizhen::BaseController before_filter :unread_messages_amount def index @topics = Topic.paginate(:page => params[:page] || 1, :conditions => "topics.group_id in (3,4,5,6)", :include => :group, :order => "topics.updated_at desc") end def show @group = Group.find(para...
Ruby
class EventCommentsController < ApplicationController before_filter :login_required before_filter :unread_messages_amount, :only => [:edit] # # full feature post comment, include upload photo def new @event = Event.find(params[:event_id]) @comment = EventComment.new end def create @event...
Ruby
class SchoolsController < ApplicationController before_filter :set_nav_session before_filter :login_required, :except => [:index, :recent, :all, :show, :search, :unconfirmed, :confirmed, :requirements, :archives, :show_date] before_filter :unread_messages_amount, :only => [:index, :unconfirmed, :confirmed, ...
Ruby
class GroupsController < ApplicationController before_filter :set_session before_filter :login_required, :except => [:show, :index] before_filter :unread_messages_amount, :only => [:new, :edit, :show, :invite_moderator, :index] def new flash[:notice] = "只有管理员才能创建" unless current_user.is_admin? @group...
Ruby
class SchoolServiceGroupsController < ApplicationController end
Ruby
# This controller handles the login/logout function of the site. class SessionsController < ApplicationController # render new.rhtml def new store_referer # record user click login from which page, and redirect to the page after login end def create self.current_user = User.authenticate(params[:...
Ruby
ActionController::Routing::Routes.draw do |map| map.bbs '/bbs/*path', :controller => 'intro', :action => 'bbs' map.home '', :controller => 'intro', :action => 'index' map.activate '/activate/:activation_code', :controller => 'users', :action => 'activate' map.help '/help', :controller => 'intro', :acti...
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).to_s end ...
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 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. Set it to :false if login fails # so tha...
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 authorize_as(user) @request.env["HTTP_AUTHORIZATION"] = user ? "Basic #{Base64.encode64("#{users(user).login}:test")}" : nil e...
Ruby
module Status MONTHS = %w(一月 二月 三月 四月 五月 六月 七月 八月 九月 十月 十一月 十二月) module School INCOMING_AVERAGE = ["未知", "< 200元", "200~500元", "500~800元", "800~1000元", "> 1000元"] module RadioBox NO = 0 YES = 1 UNKNOWN = 2 def self.status_for(status) case status when Y...
Ruby
module HtmlEngine def self.transform(text) return "" if text.to_s.empty? rc = RedCloth.new(text, [:hard_breaks]) rc.to_html(:textile) end end
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. $KCODE = 'u' require 'jcode' require 'yaml' #require_dependency 'rails_patch/text_helper' # 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' # R...
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()....
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. require 'related_select_form_options_helper' ActionView::Base.load_helpers(File.dirname(__FILE__) + "/../../lib/") module ApplicationHelper # def textilize(text) # require_library_or_gem "superredcloth" unless Object.const_def...
Ruby
module FeedHelper end
Ruby
module ArchiveHelper def is_login end end
Ruby
module TagHelper end
Ruby
module CategoryHelper end
Ruby
module NatureHelper end
Ruby
module Admin::ConfigurationHelper #before_filter :initdata def show_items items = [] #@tags_of_forum = [] items << @show_natures << @show_categories << @show_archives << @show_links << @show_statistics << @show_hot_entries << @show_last_entries << @show_hot_tags << @show_last_comments << @show_authors <...
Ruby
module Admin::AttachmentHelper end
Ruby
module Admin::UsergroupHelper end
Ruby
module Admin::UserHelper end
Ruby
module Admin::TagHelper end
Ruby
module Admin::CategoryHelper end
Ruby
module Admin::ProfileHelper end
Ruby
module Admin::CommentHelper end
Ruby
module Admin::TopicHelper end
Ruby
module Admin::TypeHelper end
Ruby
module Admin::LinkHelper end
Ruby
module PublishHelper end
Ruby
module TrackbackHelper end
Ruby
module TopicHelper end
Ruby
module IndexHelper # def subtitle # getconfig("subtitle") # end # # def about # getconfig("about") # end # # def key # getconfig("key") # end end
Ruby
class Category < ActiveRecord::Base has_many :topics belongs_to :type end
Ruby
class Nature < ActiveRecord::Base has_many :topics end
Ruby
class TrackBack < ActiveRecord::Base end
Ruby
class Topic < ActiveRecord::Base belongs_to :category ,:counter_cache => true belongs_to :type ,:counter_cache => true belongs_to :nature ,:counter_cache => true belongs_to :user ,:counter_cache => true belongs_to :tag ,:counter_cache => true has_many :comments ,:dependent => :destroy, :order => "created_a...
Ruby
#require 'rubygems' #require 'Rmagick' #require 'rmagick' #require 'Rmagic' class NoisyImage require 'RMagick' include Magick attr_reader :code, :code_image Jiggle = 15 Wobble = 15 def initialize(len) chars = ('a'..'z').to_a - ['a','e','i','o','u'] code_array=[] 1.upto(len) {code_arra...
Ruby
class UserGroup < ActiveRecord::Base has_many :users end
Ruby
class Configuration < ActiveRecord::Base end
Ruby
require "digest/sha1" class User < ActiveRecord::Base validates_confirmation_of :password, :message => "两次输入的密� �不一致,请确认..." belongs_to :user_group #,:counter_cache => true has_many :topics attr_accessor :password,:password_confirmation validates_uniqueness_of :login_name,:display_name validates_presence...
Ruby
class Tag < ActiveRecord::Base has_many :topics end
Ruby
class Comment < ActiveRecord::Base belongs_to :topic ,:counter_cache => true validates_presence_of :name,:body validates_length_of :body, :minimum => 2 validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create, :message=>"邮...
Ruby
class Type < ActiveRecord::Base has_many :categories has_many :topics end
Ruby
class Link < ActiveRecord::Base end
Ruby