code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
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
UserGroup.new(:title=>'管理员', :descripti... | 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 |
#!/usr/bin/env 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 im... | 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 |
#!/usr/bin/env 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 im... | 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 |
# 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 |
#
# To change this template, choose Tools | Templates
# and open the template in the editor.
LOG_APP_CONFIG = YAML::load(File.open("#{RAILS_ROOT}/config/appconfig.yml"))
#申请一个全局变量用来存放系统配置
$cached_configs = Hash.new
$cached_statistics = Hash.new
$application = {}
#初始化的时候加载
begin
Configuration.load_configs
Statist... | 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 |
# 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.
require 'rubygems'
$KCODE = 'u'
require 'jcode'
require 'yaml'
#gem 'soap4r'
#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
# EN... | 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.con... | Ruby |
module FeedHelper
end
| Ruby |
module TagsHelper
end
| Ruby |
module CategoriesHelper
end
| Ruby |
module Admin::TopicsHelper
def get_visible(visible)
if visible.to_s == "1"
"<%=link_to \"<font color=\"#FF0000\">隐藏</font>\",{ :action => 'notop', :id => topic }%>"
else
"隐藏"
end
end
end
| Ruby |
module Admin::CachesHelper
end
| Ruby |
module Admin::PluginsHelper
end
| Ruby |
module Admin::ConfigurationsHelper
#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 <<... | Ruby |
module Admin::UsersHelper
end
| Ruby |
module Admin::LinksHelper
end
| Ruby |
module Admin::TagsHelper
end
| Ruby |
module Admin::AttachmentsHelper
end
| Ruby |
module Admin::CategoriesHelper
end
| Ruby |
module Admin::ProfileHelper
end
| Ruby |
module Admin::IndexHelper
end
| Ruby |
module Admin::TypesHelper
end
| Ruby |
module Admin::CommentsHelper
end
| Ruby |
module Admin::ThemesHelper
end
| Ruby |
module Admin::UsergroupsHelper
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 |
module NaturesHelper
end
| Ruby |
module ArchivesHelper
def is_login
end
end
| Ruby |
class Category < ActiveRecord::Base
has_many :topics
belongs_to :type
#
def self.get_all_items(page,per_page="10")
paginate :per_page => per_page, :page => page
end
end
| Ruby |
class Statistic < ActiveRecord::Base
#从DB中加载统计信息
def self.load_statistics
logger.info("start load_statistics:$cached_statistics.size=#{$cached_statistics.size}")
get_all_statistics.each do |config|
$cached_statistics[config.name] = config.value
end
logger.info("end load_statistics:$cached_sta... | 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
#重新刷新缓存
def self.refresh_configs_cache
$cached_configs.clear
load_configs
end
#从DB中加载系统配置信息
def self.load_configs
logger.info("start load_configs:$cached_configs.size=#{$cached_configs.size}")
get_all_config.each do |config|
$cached_configs[co... | 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,:nickname
validates_presence_of ... | 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=>"邮件地址格式不正确,请检查..."
#列举全部评论
d... | Ruby |
class Type < ActiveRecord::Base
has_many :categories
has_many :topics
end
| Ruby |
class Link < ActiveRecord::Base
def self.get_all_items(page,per_page="10")
paginate :per_page => per_page, :page => page
end
def self.get_all_items_in_visible(visible,page,per_page="10")
paginate :per_page => per_page, :page => page,
:conditions => ["visible = ?",visible],
:order => 'cre... | Ruby |
class Theme < ActiveRecord::Base
#初始化
def self.load_theme_directory
themes_root = "#{RAILS_ROOT}/themes/[-_a-zA-Z0-9 ]*"
Dir.glob(themes_root).each do |file|
if File.readable?("#{file}/about.markdown") && File.directory?(file)
theme = YAML::load(File.open("#{file}/about.markdown"))
t... | Ruby |
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
def self.get_all_items(page,per_page="10")
paginate :per_page => per_page, :page => page,
:order => 'created_at DESC '
end
end
| Ruby |
require 'rubygems'
require 'youtube'
class YoutubeCell < Cell::Base
# before_filter :init_youtube
DEVELOPER_ID = "-aUPn8U5FrU"
USERNAME = 'iceskysl'
def test
"hi"
end
def youtube
youtube = YouTube::Client.new DEVELOPER_ID # Get one here: <http://youtube.com/my_profile_dev>.
... | 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
#根据提交的... | Ruby |
class ArchivesController < ApplicationController
before_filter :nav
#layout "index"
# layout :theme_layout_func
def show
@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... | Ruby |
class TagsController < 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 => [ "... | Ruby |
class NaturesController < ApplicationController
before_filter :nav
# layout "index"
# layout :theme_layout_func
def show
nature_id = params[:id]
@topics = Topic.get_items_in_nature(nature_id,params[:page],10)
rescue => err
logger.error("Attempt to access invalid Nature #{params[:id]},error=#{err}")... | Ruby |
class Admin::PluginsController < Admin::IndexController
def index
end
def list
end
def show
end
def new
end
end
| Ruby |
class Admin::AttachmentsController < Admin::IndexController
before_filter :authorize
layout "admincp"
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 => [ :destroy, :create, :update ],
:redi... | Ruby |
class Admin::ConfigurationsController < Admin::IndexController
before_filter :authorize
layout "admincp"
def index
@configurations = Configuration.find_all_by_group("String")
end
def config_show
@show_items = Configuration.find_all_by_group("Boolean")
render :layout => false
end
def... | Ruby |
class Admin::LogsController < Admin::IndexController
def index
end
def list
end
end
| Ruby |
class Admin::UsergroupsController < Admin::IndexController
before_filter :authorize
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 => [ :destroy, :create, :update ],
:re... | Ruby |
class Admin::TopicsController < Admin::IndexController
before_filter :authorize,:init_categories
layout "admincp" ,:except=>['notop']
def init_categories
@topic_categories = Category.find(:all)
@topic_natures = Nature.find(:all)
end
def index
@topics = Topic.get_all_items(params[:page],1... | Ruby |
class Admin::ThemesController < Admin::IndexController
layout "admincp"
def index
end
# def list
# themes_file
# end
def show
end
def list
@themes = Theme.find(:all,:order=>"useit DESC")
@theme = Theme.get_use_item
end
def preview
send_file(Theme.find(params[... | Ruby |
class Admin::CommentsController < Admin::IndexController
before_filter :authorize
layout "admincp"
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 => [ :destroy, :create, :update ],
:redire... | Ruby |
require "digest/sha1"
class Admin::ProfileController < Admin::IndexController
before_filter :authorize
layout "admin"
def index
@user = User.find(session[:user_id])
end
def update_profile
#@user = User.new(params[:user])
@user = User.find(session[:user_id])
if @user.update_attributes(par... | Ruby |
class Admin::CategoriesController < Admin::IndexController
before_filter :authorize
layout "admincp"
def index
@categories = Category.get_all_items(params[:id])
end
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy, :create ], :r... | Ruby |
class Admin::LinksController < Admin::IndexController
before_filter :authorize
layout "admincp"
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 => [ :destroy, :create ], :redirect_to => { :actio... | Ruby |
#require "importenv"
class Admin::IndexController < ApplicationController
before_filter :authorize,:init_user
layout "admincp"
def index
end
def show_env
render :layout => false
end
def init_user
@user = User.find(session[:user_id])
end
end
| Ruby |
class Admin::CachesController < Admin::IndexController
layout "admincp"
def index
end
def refresh
end
end
| Ruby |
class Admin::TagsController < Admin::IndexController
before_filter :authorize
layout "admincp"
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 => [ :destroy, :create, :update ],
:redire... | Ruby |
class Admin::UsersController < Admin::IndexController
before_filter :authorize
layout "admincp"
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 => [ :destroy, :create, :update ],
:redirect_to... | 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... | Ruby |
class CategoriesController < ApplicationController
before_filter :nav
#layout "index"
# layout :theme_layout_func
def show
nature_id = params[:id]
@topics = Topic.get_items_in_category(nature_id,params[:page],10)
rescue => err
logger.error("Attempt to access invalid Category #{params[:id]},msg=#... | 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 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.upd... | Ruby |
class IndexController < ApplicationController
before_filter :frist_time,:except=>['sinup','create']
before_filter :nav
#layout "index"
#layout :theme_layout_func
#首页
def index
# @lastest_topic = @topics__pages=Topic.find(:first,:order => "created_at DESC")
# @topics__pages= Topic.find(:all,:... | 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
layout 'index'
theme :initialize_theme
#选择模板
def initiali... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.