Rails 3 提供了 match
方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb
#!/usr/bin/env ruby | |
# | |
# Mac fix 1 - Install the Nokogiri gem on Mac OS 10.9 Mavericks | |
# | |
# Usage: to configure and install using Bundler, pass in 'bundle' as an argument to the script. | |
# | |
# Nokogiri works at a very low level, so it has many issues on various platforms. | |
# As a result, the command `install gem nokogiri` often will fail. This fix is for | |
# errors involving 'libiconv', such as the following one I encountered: | |
# |
" 修改leader键 | |
let mapleader = ',' | |
let g:mapleader = ',' | |
nnoremap <leader>tr :!ctags -R --languages=Ruby<CR> | |
nnoremap <leader>tj :!ctags -R --languages=Javascript<CR> | |
" set grepprg=ack\ --nogroup\ --column\ $* | |
set grepprg=ag\ --vimgrep | |
set grepformat=%f:%l:%c:%m |
#!/usr/bin/env ruby | |
REFERENCE = { | |
"add model virtual attribute" => "https://rails-bestpractices.com/posts/2010/07/21/add-model-virtual-attribute/", | |
"always add db index" => "https://rails-bestpractices.com/posts/2010/07/24/always-add-db-index/", | |
"check return value of save otherwise use save" => "https://rails-bestpractices.com/posts/2012/11/02/check-the-return-value-of-save-otherwise-use-save/", | |
"default_scope is evil" => "https://rails-bestpractices.com/posts/2013/06/15/default_scope-is-evil/", | |
"dry bundler in capistrano" => "https://rails-bestpractices.com/posts/2010/09/02/dry-bundler-in-capistrano/", | |
"isolating seed data" => "https://rails-bestpractices.com/posts/2010/07/24/isolating-seed-data/", | |
"keep finders on their own model" => "https://rails-bestpractices.com/posts/2010/07/23/keep-finders-on-their-own-model/", |
Add below code to the file `~/.bashrc` | |
# this will file recent 10 branches | |
alias recent_branches="git for-each-ref --sort='-authordate:iso8601' --format='%(refname:short)' --count 10 refs/heads" | |
function recent() { | |
read -a arr <<< $(recent_branches) | |
for ((i = 0; i < ${#arr[@]}; ++i)); do | |
position=$(($i)) |