Rails 3 提供了 match
方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb
require "fileutils" | |
root_dir = "/Users/jason/Downloads/images" | |
Dir.chdir(root_dir) | |
puts Dir.pwd | |
Dir.glob("**/*.{jpg}").each do |fname| | |
tfname = fname.split("/").last | |
if fname.match("[small|large|normal]_") | |
tfname = fname.split("_").last | |
end | |
p1,p2 = tfname[0,1],tfname[1,1] |
require 'mini_magick' | |
class CustomAdmin::MiniCaptchaController < CustomAdmin::ApplicationController | |
before_filter :clear_captcha_session, :only => :mini_captcha | |
require 'socket' | |
require 'rubygems' | |
require 'eventmachine' | |
require 'logger' | |
require 'active_record' | |
# Rails -v: 2.3.5 | |
REF_RAILS_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__),'..','..')) | |
class MobileBalanceServer < EventMachine::Connection |
# coding: utf-8 | |
module SimpleUpload | |
class Base | |
class << self | |
def max_size | |
10485760 #(10M) | |
end | |
def extension_white_list |
#!/usr/bin/env ruby | |
class NeterDbAuthorization | |
def initialize(config_file = 'config.yml') | |
# load config | |
require 'yaml' | |
@cfg = YAML.load_file(config_file) | |
# load logger | |
if @cfg['log']['file'] | |
require 'logger' |
#!/usr/bin/env ruby | |
# List all keys stored in memcache. | |
# Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place. | |
require 'net/telnet' | |
headings = %w(id expires bytes cache_key) | |
rows = [] |
require 'rubygems' | |
require 'blather/client' | |
# CONFIGURATION | |
jid = '[email protected]' | |
password = "foofoo" | |
chatroom = "[email protected]" | |
setup(jid, password) |
#!/usr/bin/env ruby | |
require 'logger' | |
require 'rest_client' | |
$stdout.sync = true | |
$stdin.sync = true | |
path = "/usr/local/var/log/ejabberd/auth.log" | |
file = File.open(path, File::WRONLY | File::APPEND | File::CREAT) |