code
stringlengths
1
1.73M
language
stringclasses
1 value
#!H:/InstantRails/ruby/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 seve...
Ruby
#!H:/InstantRails/ruby/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/fastcg...
Ruby
#!H:/InstantRails/ruby/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 seve...
Ruby
#!H:/InstantRails/ruby/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 seve...
Ruby
#!H:/InstantRails/ruby/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/fastcg...
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
class AddPostCatgoryId < ActiveRecord::Migration def self.up add_column :posts, :category_id, :integer end def self.down remove_column :posts, :category_id, :integer end end
Ruby
class AddPostsColumn < ActiveRecord::Migration def self.up add_column :posts, :attachment_id, :string, :default => "" #附件 add_column :posts, :user_id, :integer, :default => 0 #发表者ID add_column :posts, :views_count, :integer, :default => 0 #查看次数 add_column :posts, :comments_count, :integer, :def...
Ruby
class CreateTags < ActiveRecord::Migration def self.up create_table :tags do |t| t.string :name t.timestamps end end def self.down drop_table :tags end end
Ruby
class CreateComments < ActiveRecord::Migration def self.up create_table :comments do |t| t.integer :post_id t.text :body t.timestamps end end def self.down drop_table :comments end end
Ruby
class AddCommentUserId < ActiveRecord::Migration def self.up add_column :comments, :user_id , :integer, :default => 0 end def self.down remove_column :comments, :user_id , :integer end end
Ruby
class AddPostTagId < ActiveRecord::Migration def self.up add_column :posts, :tag_id, :integer end def self.down remove_column :posts, :tag_id, :integer end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :name t.string :hashed_password t.string :salt t.timestamps end end def self.down drop_table :users end end
Ruby
class CreatePosts < ActiveRecord::Migration def self.up create_table :posts do |t| t.string :title t.text :body t.boolean :published t.timestamps end end def self.down drop_table :posts end end
Ruby
class CreateCategories < ActiveRecord::Migration def self.up create_table :categories do |t| t.string :name t.timestamps end end def self.down drop_table :categories end end
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
#!C:/Program Files/ruby/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 sev...
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
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module Admin::IndexHelper end
Ruby
module Admin::UsersHelper end
Ruby
module Admin::PostsHelper end
Ruby
module Admin::CategoriesHelper end
Ruby
module Admin::TagsHelper end
Ruby
module LoginHelper end
Ruby
module UsersHelper end
Ruby
module AdminHelper end
Ruby
module PostsHelper end
Ruby
module CategoriesHelper end
Ruby
module TagsHelper end
Ruby
module CommentsHelper end
Ruby
class Post < ActiveRecord::Base has_many :comments has_one :category # has_and_belongs_to_many :tags # validate the data validates_presence_of :title, :body, :category_id end
Ruby
class Tag < ActiveRecord::Base end
Ruby
class Comment < ActiveRecord::Base belongs_to :post validates_presence_of :body end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name # 不需要生成散列码 attr_accessor :password_confirmation validates_confirmation_of :password def validate errors.add_to_base("Missing password") if hashed_password.blank? end # 只读方法 def passwo...
Ruby
class Category < ActiveRecord::Base has_many :posts end
Ruby
class PostsController < ApplicationController before_filter :initilize, :only => [:new, :create, :edit, :update] # GET /posts # GET /posts.xml def index # @posts = Post.find(:all, :conditions => ['published <> 0' ] ,:order => "created_at DESC") @posts = Post.paginate :page => params[:page], :per_page => ...
Ruby
class CommentsController < ApplicationController before_filter :authorize # GET /comments # GET /comments.xml def index @comments = Comment.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @comments } end end # GET /comments/1 # GET /...
Ruby
class CategoriesController < ApplicationController layout 'posts' # GET /categories # GET /categories.xml def index @categories = Category.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @categories } end end # GET /categories/1 # GET ...
Ruby
class Admin::PostsController < Admin::IndexController before_filter :authorize before_filter :initilize, :only => [:new, :create, :edit, :update] layout 'admin' # GET /posts # GET /posts.xml def index @posts = Post.find(:all) respond_to do |format| format.html # index.html.e...
Ruby
class Admin::CommentsController < Admin::IndexController # GET /comments # GET /comments.xml def index @comments = Comment.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @comments } end end # GET /comments/1 # GET /comments/1.xml de...
Ruby
class Admin::CategoriesController < Admin::IndexController layout 'admin' # GET /categories # GET /categories.xml def index @categories = Category.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @categories } end end # GET /categories/1 ...
Ruby
class Admin::UsersController < Admin::IndexController before_filter :authorize # GET /users # GET /users.xml def index @users = User.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end # GET /users/1 ...
Ruby
class Admin::TagsController < Admin::IndexController layout 'admin' # GET /tags # GET /tags.xml def index @tags = Tag.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @tags } end end # GET /tags/1 # GET /tags/1.xml def show @tag =...
Ruby
class Admin::IndexController < ApplicationController before_filter :authorize,:init_user layout "admin" def index end def show_env render :layout => false end def init_user @user = User.find(session[:user_id]) end end
Ruby
class LoginController < ApplicationController # 同样使用post模板,即front界面 layout 'posts' before_filter :authorize, :except => :login # 使用postback处理, GET请求,就是空表单,如果包含数据,就是POST请求。 def login session[:user_id] = nil user = User.authentication(params[:name], params[:password]) if user session[:u...
Ruby
class UsersController < ApplicationController layout 'admin' # GET /users # GET /users.xml def index @users = User.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @users } end end # GET /users/1 # GET /users/1.xml def show @user ...
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 # See ActionController::RequestForgeryProtection for details...
Ruby
class TagsController < ApplicationController layout 'posts' # GET /tags # GET /tags.xml def index @tags = Tag.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @tags } end end # GET /tags/1 # GET /tags/1.xml def show @tag = Tag.fin...
Ruby
class AdminController < ApplicationController before_filter :authorize def list end 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
# 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| # 按照由上到下的顺序匹配URL #admin map.namespace(:admin) do |admin| admin.resources :users admin.resources :posts do |post| post.resources :comments end admin.resources :categories admin.resources :tags end # front map.root :controller ...
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
class CreateAccounts < ActiveRecord::Migration def self.up create_table :accounts do |t| t.string :name t.string :number t.timestamps end end def self.down drop_table :accounts end end
Ruby
class CreateTransactions < ActiveRecord::Migration def self.up create_table :transactions do |t| t.date :date t.string :number t.string :payee_category t.float :amount t.boolean :credit t.references :account t.timestamps end end def self.down drop_table :tra...
Ruby
class CreateCategories < ActiveRecord::Migration def self.up create_table :categories do |t| t.string :name t.boolean :credit t.timestamps end end def self.down drop_table :categories end end
Ruby
class CreatePayees < ActiveRecord::Migration def self.up create_table :payees do |t| t.string :name t.string :phone_number t.timestamps end end def self.down drop_table :payees end end
Ruby
class CreateBills < ActiveRecord::Migration def self.up create_table :bills do |t| t.references :payee t.references :account t.string :number t.date :next_payment_date t.string :payment_method t.string :frequency t.float :amount t.references :category t.boolea...
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
#!C:/ruby/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...
Ruby
#!C:/ruby/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 #...
Ruby
#!C:/ruby/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...
Ruby
#!C:/ruby/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...
Ruby
#!C:/ruby/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 #...
Ruby
#!C:/ruby/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...
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby