code
stringlengths
1
1.73M
language
stringclasses
1 value
class CreateBoards < ActiveRecord::Migration def self.up create_table :boards do |t| t.string :title t.string :name t.text :description t.integer :group_id t.integer :posts_count, :default => 0 t.timestamps end end def self.down drop_table :boards end end
Ruby
class CreateClips < ActiveRecord::Migration def self.up create_table :clips do |t| t.column :size, :integer # file size in bytes t.column :content_type, :string # mime type, ex: application/mp3 t.column :filename, :string # sanitized filename t.column :height, :integer # i...
Ruby
class CreateGroups < ActiveRecord::Migration def self.up create_table :groups do |t| t.string :title t.string :name t.text :description t.integer :boards_count, :default => 0 t.timestamps end # Create default 'home' group Group.create :name => 'home', :title => 'Hom...
Ruby
class CreatePermissions < ActiveRecord::Migration def self.up create_table :permissions do |t| t.integer :user_id t.integer :role_id t.timestamps end remove_column :users, :admin admin = User.first admin_role = Role.create(:name => 'admin', :description => 'Admin') Permissio...
Ruby
class CreateReplies < ActiveRecord::Migration def self.up create_table :replies do |t| t.text :body t.string :ip, :limit => 15 t.integer :user_id, :post_id t.string :author, :password, :homepage t.boolean :secret, :defalut => false t.timestamps end end def self.down d...
Ruby
class ActsAsTaggableMigration < ActiveRecord::Migration def self.up create_table :tags do |t| t.column :name, :string end create_table :taggings do |t| t.column :tag_id, :integer t.column :taggable_id, :integer # You should make sure that the column created is...
Ruby
class AddOpenLevelToPost < ActiveRecord::Migration def self.up add_column :posts, :open_level, :integer, :default => 99 end def self.down remove_column :posts, :open_level end end
Ruby
class CreateFriendships < ActiveRecord::Migration def self.up create_table :friendships, :force => true do |t| t.column "user_id", :integer, :null => false t.column "friend_id", :integer, :null => false t.column "created_at", :datetime t.column "accepted_at", :datetime end en...
Ruby
class CreateDiggs < ActiveRecord::Migration def self.up create_table :diggs do |t| t.integer :user_id t.integer :post_id t.string :ip, :limit => 24 t.timestamps end end def self.down drop_table :diggs end end
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' require 'redgreen' 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...
Ruby
#!/usr/local/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 impai...
Ruby
#!/usr/local/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.lo...
Ruby
#!/usr/local/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 impai...
Ruby
#!/usr/local/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 impai...
Ruby
#!/usr/local/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.lo...
Ruby
#!/usr/local/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 impai...
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/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/destroy'
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/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/dbconsole'
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/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/dbconsole'
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/plugin'
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/spawner'
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/reaper'
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/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/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/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
xml.instruct! xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do xml.channel do xml.title @group.title xml.link g_path(@group) xml.pubDate CGI.rfc1123_date @posts.first.created_at if @posts.any? xml.description @group.description @posts.each do |post| xml.item do ...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper include TagsHelper end
Ruby
module SessionsHelper end
Ruby
module FriendshipsHelper def user_link(user) link_to image_tag(user.avatar.url(:thumb)), user_path(user) end end
Ruby
module UsersHelper end
Ruby
module Zi2Helper def display_tree_recursive(tree, parent_id) ret = "\n<ul id=\"category\">" tree.each do |node| if node.parent_id == parent_id ret += "\n\t<li>" ret += yield node ret += display_tree_recursive(tree, node.id) { |n| yield n } unless node.children.empty? ...
Ruby
module Zi2::GbpHelper #def g_path(group=nil); url_for(:controller => get_group(group), :action => 'list') end #def gb_path(board); url_for(:controller => board.group.to_s, :board => board.to_s, :action => 'index') end #def new_gbp_path(board); url_for(:controller => board.group.to_s, :board => board.to_s, :actio...
Ruby
class Clip < ActiveRecord::Base belongs_to :post, :counter_cache => true has_attachment :storage => :file_system, #:processor => 'RMagick', :resize_to => '700x', :thumbnails => { :thumb => [70, 70] }, :max_size => 2.megabytes validates_as_attachment end
Ruby
class Digg < ActiveRecord::Base belongs_to :post, :counter_cache => true end
Ruby
class Friendship < ActiveRecord::Base belongs_to :friendshipped_by_me, :foreign_key => "user_id", :class_name => "User" belongs_to :friendshipped_for_me, :foreign_key => "friend_id", :class_name => "User" # TODO: Add some friendly accessor methods here end
Ruby
class Post < ActiveRecord::Base belongs_to :user has_many :clips, :dependent => :destroy has_many :replies, :order => 'created_at' has_many :diggs, :dependent => :delete_all belongs_to :board, :counter_cache => true validates_presence_of :title, :content acts_as_taggable #acts_as_indexed :fields => [:titl...
Ruby
class Board < ActiveRecord::Base has_many :posts, :order => 'created_at DESC' belongs_to :group, :counter_cache => true validates_presence_of :title, :name validates_uniqueness_of :name, :message => "는 이미 사용중입니다." end
Ruby
class OpenLevel PRIVATE=1 FRIENDS_ONLY=2 MEMBERS_ONLY=3 PUBLIC=99 def self.options [['비밀글', PRIVATE], ['지인공개', FRIENDS_ONLY], ['회원공개', MEMBERS_ONLY], ['전체공개', PUBLIC]] end end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base has_many :posts has_many :replies has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions has_attached_file :avatar, :url => "/:class/:attachment/:id/:style_:basename.:extension", :path => ":rails_root/pu...
Ruby
class Reply < ActiveRecord::Base belongs_to :user belongs_to :post, :counter_cache => true validates_presence_of :author, :unless => :has_logged_in_user? named_scope :public_only, :conditions => ['secret = ?', false] def has_logged_in_user? !self.user.nil? end end
Ruby
class Permission < ActiveRecord::Base belongs_to :user belongs_to :role end
Ruby
class Role < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :users, :through => :permissions end
Ruby
class Group < ActiveRecord::Base has_many :boards validates_presence_of :title, :name validates_uniqueness_of :name, :message => "는 이미 사용중입니다." def self.options self.find(:all).collect {|g| [ g.title, g.id ] } end end
Ruby
class HomeController < Zi2::PostsController # Do not delete this! end
Ruby
class UsersController < ApplicationController before_filter :login_required, :except => [:show, :new, :create] def new @user = User.new end def create cookies.delete :auth_token # protects against session fixation attacks, wreaks havoc with # request forgery protection. # uncomment at your...
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 # Be sure to include AuthenticationSystem in Application Controller instead include AuthenticatedSystem, Zi2:...
Ruby
class Zi2::PostsController < ApplicationController before_filter :login_required, :except => [:list, :index, :show, :catch_all] before_filter :set_group_board #, :only => [:list, :index, :new, :create] layout 'zi2/posts/inner' inherit_views PER_PAGE = 10 # GET /group def list real_list render_t...
Ruby
class Zi2::Admin::PostsController < Zi2::Admin::AdminController PER_PAGE = 10 def index filters = ConditionFilter.new if category_id = params[:category_id] @category = Category.find(category_id) categories = @category.self_and_descendants.map(&:id) filters << ['category_id IN (?)', categ...
Ruby
class Zi2::Admin::BoardsController < Zi2::Admin::AdminController PER_PAGE = 20 make_resourceful do actions :all before :new do current_object.group_id = params[:group] end after :create do flash[:notice] = '새 게시판이 생성되었습니다.' end response_for :create, :update, :de...
Ruby
class Zi2::Admin::UsersController < Zi2::Admin::AdminController PER_PAGE = 3 def index @users = User.all.paginate :page => params[:page], :per_page => PER_PAGE end end
Ruby
class Zi2::Admin::GroupsController < Zi2::Admin::AdminController PER_PAGE = 10 make_resourceful do actions :all after :create do flash[:notice] = "\"#{@group.title}\" 그룹이 생성되었습니다." end response_for :create, :update, :destroy do |format| format.html { redirect_to admin_groups_...
Ruby
class Zi2::Admin::AdminController < ApplicationController layout 'zi2/admin' before_filter :check_administrator_role end
Ruby
class Zi2::ClipsController < ApplicationController def destroy @clip = Clip.find(params[:id]) @clip.destroy respond_to do |format| format.js do render :update do |page| page << "$('#clip_#{@clip.id}').remove();" end end end #render :nothing => true end end
Ruby
class Zi2::RepliesController < ApplicationController before_filter :get_post def create @reply = @post.replies.build(params[:reply]) @reply.ip = request.remote_addr @reply.user = current_user if logged_in? @reply.save redirect_to gbp_path(@post) + "#reply_#{@reply.id}" end private def get_...
Ruby
class Zi2::FriendshipsController < ApplicationController before_filter :login_required before_filter :get_both_side, :except => [:index] # GET /users/:user_id/friendships def index @user = User.find_by_login(params[:user_id]) if @user == current_user @friends = @user.friends @pendings_for_me = @user.pen...
Ruby
# This controller handles the login/logout function of the site. class SessionsController < ApplicationController # render new.rhtml def new end def create if using_open_id? open_id_authentication(params[:openid_url]) else password_authentication(params[:login], params[:password]) end end de...
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
ActiveSupport::CoreExtensions::Time::Conversions::DATE_FORMATS.merge!( :kymd => "%Y-%m-%d", :kmd => "%m월%d일", :klong => "%Y-%m-%d %H:%M:%S" )
Ruby
# Set tag deliminator from comma to blank TagList.delimiter = " "
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
ActionController::Routing::Routes.draw do |map| map.resources :users map.resources :users do |users| users.resources :friendships, :member => { :ask => :put, :accept => :put }, :controller => 'zi2/friendships' end map.open_id_complete 'session', :controller => 'sessions', :action => 'create', :condition...
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
# 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
# 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 end # Accesses the current user from the session. # Future calls avoid the database because nil is not...
Ruby
module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user_id] = user ? users(user).id : nil end def authorize_as(user) @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials...
Ruby
module Searchable def searchable_by(*column_names) @search_columns = [] [column_names].flatten.each do |name| @search_columns << name end end def search(query, fields=nil, options={}) with_scope :find => { :conditions => search_conditions(query, fields) } do find :all, options end end ...
Ruby
class Zi2Generator < Rails::Generator::NamedBase def manifest record do |m| m.class_collisions class_name #m.directory('public/stylesheets') #m.file('application.css', 'public/stylesheets/application.css') m.directory("app/views/#{file_name}") m.template('controller_template.rb', "app...
Ruby
class <%= class_name %>Controller < Zi2::PostsController end
Ruby
require 'mkmf' $CPPFLAGS = $CPPFLAGS + " -I../../include" $LDFLAGS = $LDFLAGS + " -L../../" $LIBS = $LIBS + " -lhpdf -lpng -lz" create_makefile 'hpdf'
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- demo.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appea...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- encryption.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- font_example.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright noti...
Ruby
# # << Haru Free PDF Library 2.0.2 >> -- arc_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appear ...
Ruby
# # << Haru Free PDF Library 2.0.6 >> -- ext_gstate_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice ...
Ruby
# # << Haru Free PDF Library 2.0.2 >> -- ttfont_demo.rb # # http://libharu.org/ # # Copyright (c) 1999-2006 Takeshi Kanno # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice appe...
Ruby
# # << Haru Free PDF Library 2.0.0 >> -- text_demo2.rb # # Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp> # # Permission to use, copy, modify, distribute and sell this software # and its documentation for any purpose is hereby granted without fee, # provided that the above copyright notice...
Ruby