Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb| # 30 minutes Lisp in Ruby | |
| # Hong Minhee <http://dahlia.kr/> | |
| # | |
| # This Lisp implementation does not provide a s-expression reader. | |
| # Instead, it uses Ruby syntax like following code: | |
| # | |
| # [:def, :factorial, | |
| # [:lambda, [:n], | |
| # [:if, [:"=", :n, 1], | |
| # 1, |
| #encoding: utf-8 | |
| require "fileutils" | |
| namespace :my_db do desc "Backup project database. Options: DIR=backups RAILS_ENV=production MAX=7" | |
| desc "usage - bundle exec rake my_db:backup RAILS_ENV=production MAX=15 DIR=db/db.bak" | |
| task :backup => [:environment] do | |
| # config base dir | |
| datestamp = Time.now.strftime("%Y%m%d%H%M") | |
| base_path = Rails.root | |
| backup_folder = File.join(base_path, ENV["DIR"] || "backups") | |
| FileUtils.mkdir_p(backup_folder) unless File.exist?(backup_folder) |
| Alt + F11 进入宏编辑界面 | |
| ======================================== | |
| ' 当前宏对excel的操作与excel的事件冲突时 | |
| Application.EnableEvents = False | |
| ' Your Code' | |
| Application.EnableEvents = True | |
| ========================================= | |
| ' 禁止删除行 | |
| Application.CommandBars("Cell").Controls(6).Enabled = False |
| // Settings in here override those in "Default/Preferences.sublime-settings", and | |
| // are overridden in turn by file type specific settings. | |
| { | |
| "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme", | |
| "font_face": "Monaco", | |
| "font_size": 14, | |
| // Valid options are "no_bold", "no_italic", "no_antialias", "gray_antialias", | |
| // "subpixel_antialias" and "no_round" (OS X only) | |
| // 字体选项:no_bold 不显示粗体字,no_italic 不显示斜体字,no_antialias 和 no_antialias 关闭反锯齿 | |
| // subpixel_antialias 和 no_round 是 OS X 系统独有的 |
| #Model | |
| @user.should have(1).error_on(:username) # Checks whether there is an error in username | |
| @user.errors[:username].should include("can't be blank") # check for the error message | |
| #Rendering | |
| response.should render_template(:index) | |
| #Redirecting | |
| response.should redirect_to(movies_path) |
| <!-- | |
| 监视input输入为手机号 | |
| 即输入内容为11位数字 | |
| --> | |
| <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> | |
| <input type="text" id="number"> | |
| <script> | |
| function chk_phone_number(input) { | |
| if(input.val().toString().match(/^[-]?[0-9]+[\.]?[0-9]*$/)==null || |
| ctrl+a 跳到行首 | |
| ctrl+e 跳到末尾 | |
| ctrl+d 删除光标后1个字符 | |
| ctrl+h 删除光标前1个字符 | |
| ctrl+u 清除至行首 | |
| ctrl+k 清除至行尾 | |
| ctrl+f 光标后移1个字符 |
| <div id="picture_show" style="position: absolute; display: none; background: none repeat scroll 0% 0% rgb(211, 211, 211); border-radius: 5px;z-index: 10000; "> | |
| <img> | |
| </div> | |
| //picture show orginal size | |
| $("#picture_list img").each(function(){ | |
| $img = $(this); | |
| $tooltip = $("#picture_show"); | |
| $img.hover( |
| bundle install --path vendor/bundle | |
| gem install rails -v 版本号 |