code
stringlengths
1
1.73M
language
stringclasses
1 value
class SingleFile < ActiveRecord::Base def self.save(topic) @attachment = Attachment.new @uploaded_file = topic['attachment_id'] @filename = sanitize_filename(@uploaded_file.original_filename) @attachment.filename = @filename @attachment.filetype = @uploaded_file.content_type if @attachment....
Ruby
class Attachment < ActiveRecord::Base belongs_to :topic end
Ruby
require 'net/http' require 'uri' require 'rexml/document' require 'rss/1.0' require 'rss/2.0' class PublishController < ApplicationController before_filter :nav before_filter :authorize,:only=>['index','create_by_rss'] layout "index" def index @tags = Tag.find(:all) @topic = Topic.new end #根据提交的RSS 的URL ...
Ruby
class NatureController < ApplicationController before_filter :nav # layout "index" layout :theme_layout_func def index topic_nature_id = params[:id] @lastest_topic = Topic.find(:first,:conditions => [ "nature_id = ?", topic_nature_id],:order => "created_at DESC") @topics__pages=Topic.find(:all,:condit...
Ruby
class CategoryController < ApplicationController before_filter :nav #layout "index" layout :theme_layout_func def index topic_category_id = params[:id] @lastest_topic = Topic.find(:first,:conditions => [ "category_id = ?", topic_category_id],:order => "created_at DESC") @topics__pages=Topic.find(:all...
Ruby
class TagController < ApplicationController before_filter :nav #layout "index" layout :theme_layout_func def index topic_tag_id = params[:id] @lastest_topic = Topic.find(:first,:conditions => [ "tag_id = ?", topic_tag_id],:order => "created_at DESC") @topics__pages=Topic.find(:all,:conditions => [ "t...
Ruby
class Admin::CategoryController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only ...
Ruby
class Admin::UsergroupController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only...
Ruby
class Admin::AttachmentController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :onl...
Ruby
class Admin::UserController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ ...
Ruby
class Admin::TypeController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [...
Ruby
class Admin::TagController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ ...
Ruby
require "digest/sha1" class Admin::ProfileController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index @user = User.find(session[:user_id]) end def update_profile #@user = User.new(params[:user]) @user = User.find(sess...
Ruby
class Admin::ConfigurationController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index @configurations = Configuration.find :all end def config_show end def config_num end def config_theme @app_theme = ...
Ruby
class Admin::LinkController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [...
Ruby
class Admin::TopicController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" ,:except=>['notop'] def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method...
Ruby
class Admin::CommentController < ApplicationController before_filter :authorize,:only=>['new','create','edit','update','destroy'] layout "admin" def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only =...
Ruby
require 'rubygems' require 'net/http' require 'uri' require_gem 'builder' class TrackbackController < ApplicationController #before_filter :set_xml_header def index #接收加密码 @key = LOG_APP_CONFIG["KEY"] @code = params[:id] logger.error("code #{@code.to_s}") de_code = decode64(@code.to_s).to...
Ruby
require 'rss/maker' class FeedController < ApplicationController def index topics = Topic.find :all, :order => "created_at DESC " feed = RSS::Maker.make("2.0") do |maker| maker.channel.title = "Ruby On Rails Techlogs --1ster..!" maker.channel.description = "Ruby On Rails Techlogs:TopicsRSS" ...
Ruby
class ArchiveController < ApplicationController before_filter :nav #layout "index" layout :theme_layout_func def index @year = params[:year].to_i @month= params[:month].to_i time_at=Date.new(@year,@month) # @topics = Topic.find(:all,:conditions => [ "date_format(created_at,'%Y%M') = ?",date_format(time_at...
Ruby
class TopicController < ApplicationController #model :noisy_image before_filter :nav layout "index" #layout :theme_layout_func def index # session[:noisy_image] = NoisyImage.new(4) #生成一个有4字符的图片 # session[:code] = session[:noisy_image].code @topic = Topic.find(params[:id]) @topic.update_attribut...
Ruby
class IndexController < ApplicationController before_filter :frist_time,:except=>['sinup','create'] before_filter :nav #layout "index" layout :theme_layout_func def index @lastest_topic = Topic.find(:first,:order => "created_at DESC") @topics__pages=Topic.find(:all,:order => "istop DESC,created_at...
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. require 'related_select_form_options_helper' class ApplicationController < ActionController::Base #model :noisy_image before_filter :initdata before_filter :init...
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 CreateConfigurations < ActiveRecord::Migration def self.up create_table :configurations do |t| t.column :name, :string #名 t.column :title, :string #看到的名 t.column :description, :string #描述 t.column :value, :text #值 end Configuration.new(:name=>"name",:title=>'博客名称', :description=>...
Ruby
class CreateLinks < ActiveRecord::Migration def self.up create_table :links do |t| t.column :parent_id, :integer ,:default => 0 #小分类的父类 0代表是父类 t.column :title, :string t.column :description, :string t.column :weburl, :string, :default => "http://" t.column :position ,:integer t.column ...
Ruby
class CreateNatures < ActiveRecord::Migration def self.up create_table :natures do |t| t.column :title, :string #性质 原创 转载 翻译 t.column :description, :string #描述 t.column :topics_count, :integer, :default => 0 #文章数 t.column :position, :integer ,:default => 0 #排列顺序 end Nature.ne...
Ruby
class CreateTrackBacks < ActiveRecord::Migration def self.up create_table :track_backs do |t| t.column :topic_id, :integer #文章ID t.column :title, :string ,:default => "TrackBack Titel" t.column :excerpt, :string ,:default => "TrackBack Excerpt" t.column :blog_name, :string ,:default => "Blog N...
Ruby
class CreateAttachments < ActiveRecord::Migration def self.up create_table :attachments do |t| t.column :topic_id,:integer #主题ID t.column :filename, :string #文件名 t.column :filetype, :string #类型 t.column :filesize, :integer, :default => 0 #大小 t.column :filepath, :string, :default ...
Ruby
class InitConfig < ActiveRecord::Migration def self.up Configuration.new(:name=>"theme",:title=>'显示模板', :description=>'选择你喜欢的显示模板',:value=>'simple').save Configuration.new(:name=>"editor",:title=>'编辑器', :description=>'选择你喜欢的编辑器',:value=>'textile').save end def self.down end end
Ruby
class CreateTypes < ActiveRecord::Migration def self.up create_table :types do |t| t.column :title, :string #大类分类名 新闻 博客 公告 t.column :description, :string #大类分类描述 t.column :topics_count, :integer, :default => 0 #文章数 t.column :position, :integer ,:default => 0 #排列顺序 end Type.n...
Ruby
class CreateComments < ActiveRecord::Migration def self.up create_table :comments do |t| t.column :body,:text #内容 t.column :type_id,:integer #大分类ID t.column :topic_id,:integer #主题ID t.column :name,:string #回复者姓名 t.column :email,:string, :default => " @ " #回复者EAMIL t.column...
Ruby
class CreateTags < ActiveRecord::Migration def self.up create_table :tags do |t| t.column :title, :string t.column :description, :string t.column :topics_count, :integer ,:default => 0 end end def self.down drop_table :tags end end
Ruby
class AddTrackBacksCount < ActiveRecord::Migration def self.up add_column :topics, :track_backs_count, :integer , :default => 0 # 文章引用数 end def self.down remove_column :topics, :track_backs_count end end
Ruby
class AddNatureId < ActiveRecord::Migration def self.up add_column :topics, :nature_id, :integer , :default => 1 # 分类ID end def self.down remove_column :topics, :nature_id end end
Ruby
class CreateTopics < ActiveRecord::Migration def self.up create_table :topics do |t| t.column :title, :string #标题 t.column :body, :text #内容 t.column :created_at, :datetime #发表时间 t.column :updated_at, :datetime t.column :type_id, :integer, :default => 0 #大类别 新闻 博客 文章 ...
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.column :login_name, :string #登录名 t.column :display_name, :string#现实名 t.column :hashed_pass,:string #密码 t.column :email,:string #油箱 t.column :im,:string #IM t.column :personality,:t...
Ruby
class CreateCategories < ActiveRecord::Migration def self.up create_table :categories do |t| t.column :type_id, :integer, :default => 0 #大类别 新闻 博客 文章 t.column :title, :string #小类分类名 新闻 博客 公告的二级分类 t.column :description, :string #小分类分类描述 t.column :position, :integer ,:default => 0 ...
Ruby
class CreateUserGroups < ActiveRecord::Migration def self.up create_table :user_groups do |t| t.column :title, :string #人群分类名 管理员 设计师 用户等 t.column :description, :string #人群分类描述 t.column :users_count, :integer, :default => 0 #用户数,计数器缓存 end end def self.down drop_table :user...
Ruby
# We use this chunk of controller code all over to generate PDF files. # # To stay DRY we placed it here instead of repeating it all over the place. # module PdfHelper require 'prince' private # Makes a pdf, returns it as data... def make_pdf(template_path, pdf_name, landscape=false) prince = Prince....
Ruby
#!/usr/bin/ruby # Backs up the databases of applications on Rails Machine. # This script is intended to be called by cron on your Rails Machine. # # Andrew Stewart, AirBlade Software Ltd (boss at airbladesoftware dot com) # Feedback gratefully received. # # Version 0.1 require 'rubygems' require 'logger' ...
Ruby
#-- # Copyright (C) 2006 Dimitrij Denissenko # Please read LICENCE document for more information. #++ module ActionView #:nodoc: module Helpers #:nodoc: # This plugin adds a new helper to the great RubyOnRails framework that # allows to generate multiple, dependent HTML select tags. It handles # the re...
Ruby
#!/usr/bin/ruby # Backs up the databases of applications on Rails Machine. # This script is intended to be called by cron on your Rails Machine. # # Andrew Stewart, AirBlade Software Ltd (boss at airbladesoftware dot com) # Feedback gratefully received. # # Version 0.1 require 'rubygems' require 'logger' ...
Ruby
module ActionView module Helpers module TextHelper ALLOWED_TAGS = %w(a img) unless defined?(ALLOWED_TAGS) def whitelist(html) #only do this if absolutely necessary if html.index("<") tokenizer = HTML::Tokenizer.new(html) new_te...
Ruby
# Prince XML Ruby interface. # http://www.princexml.com # # Library by Subimage Interactive - http://www.subimage.com # # # USAGE # ----------------------------------------------------------------------------- # prince = Prince.new() # html_string = render_to_string(:template => 'some_document') # send_data( # ...
Ruby
#!D:/soft/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 imp...
Ruby
#!D:/soft/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 imp...
Ruby
#!/usr/bin/env 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
#!D:/soft/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 imp...
Ruby
#!/usr/bin/env 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
#!D:/soft/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 imp...
Ruby
#!D:/soft/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....
Ruby
#!D:/soft/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....
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. $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' # ...
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