Skip to content

Instantly share code, notes, and snippets.

View chechaoyang's full-sized avatar

Che Chaoyang chechaoyang

View GitHub Profile
@nightire
nightire / Changes in Rails 4_1.md
Last active May 11, 2022 04:50
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@xain
xain / rails_admin.zh-CN.yml
Created August 5, 2012 07:27
rails_admin.zh-CN.yml
zh-CN:
admin:
home:
name: "首页"
pagination:
previous: "« 上一页"
next: "下一页 »"
truncate: "…"
misc:
filter_date_format: "mm/dd/yy" # a combination of 'dd', 'mm' and 'yy' with any delimiter. No other interpolation will be done!
class ActionDispatch::Routing::Mapper
def draw(routes_name)
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb")))
end
end
BCX::Application.routes.draw do
draw :api
draw :account
draw :session
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@tomazzlender
tomazzlender / unicorn
Created February 22, 2012 14:24 — forked from shapeshed/unicorn
unicorn init.d
/usr/sbin/update-rc.d -f unicorn defaults
chmod +x /etc/init.d/unicorn
/usr/sbin/update-rc.d -f unicorn remove
@bryckbost
bryckbost / gist:1040263
Created June 22, 2011 14:54
Capybara 1.0 and Chrome
# env.rb
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Download chromedriver from http://code.google.com/p/selenium/downloads/list
mv chromedriver to /usr/local/bin so it's in your path.
@mrrooijen
mrrooijen / Capistrano-Deployment-Recipe.rb
Created July 29, 2009 09:34
a "base" Capistrano Rails Deployment Recipe. Use it to deploy your Rails application. It is also easily expandable. So feel free to grab this Recipe and add your own tasks/customization!
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
class Module
def subclasses
classes = []
ObjectSpace.each_object do |klass|
next unless Module === klass
classes << klass if self > klass
end
classes
end
end