工作上 rails 在每個 stage 的 domain 長度都不太一樣
例如 production 是 example.com,staging 是 kerkerj.staging.example.com
MyApp::Application.config.session_store :redis_session_store, { key: 'example_session_token', domain: :all, tld_length: 4, serializer: :hybrid, redis: { host: "....", key_prefix: "...", expire_after: 7.day, } } 相關原始碼: action_dispatch/middleware/cookies.rb
在這裡的 tld_length 就是看你 domain 的 tld 想設定到哪就寫多少
以 kerkerj.staging.example.com 為例,想要 example.com 就是 2,想要 kerkerj.staging.example.com 就是 4
而在 Rails App 裡,在 config.action_dispatch.tld_length (或 ActionDispatch::Http::URL.tld_length ) 設定的 tld_length
在 rails api document 的 #domain 有用法
如果 rails app 裡的 initializer 有載入順序的需求的話
可以照著 Ruby On Rails Guide 這篇來設定
If you have any ordering dependency in your initializers, you can control the load order through naming. Initializer files are loaded in alphabetical order by their path. For example, 01_critical.rb will be loaded before 02_normal.rb.
檔名加個數字前綴,rails 就會以數字順序來依序載入~
詳細的東西還是看 project’s github page 比較快 - Capistrano@github
Capistrano 剛開始寫 deploy script 時真的會有點搞不太懂 XD
記錄一下使用 ‘capistrano’ 把特定的 github repo 抓到 remote server
安裝 先在 Gemfile 加入:
gem 'capistrano', '~> 3.2.0' 然後安裝~
bundle install 步驟大概會是:
假設已經寫完 capistrano 了,執行 script 時,
capistrano 會先利用 script 裡提供的 server ip 以及 public key,
先連線到 remote server,接著再到 github 上拉 code 到指定的目錄裡,
再重開 server。
產生相關檔案 bundle exec cap install 會產生以下檔案: (copy from Capistrano@github)
├── Capfile ├── config │ ├── deploy │ │ ├── production.
nodejs v0.10.25 (for rails javascript engine) rbenv 0.4.0-98-g13a474c ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux] Rails 4.1.4 nginx version: nginx/1.6.0 Phusion Passenger version 4.0.48 mysql Ver 14.14 Distrib 5.5.38, for debian-linux-gnu (x86_64) using readline 6.3 Installing Ruby & Rails sudo apt-get update && sudo apt-get upgrade sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties nodejs npm Use rbenv
cd git clone git://github.
change
protect_from_forgery with: :exception
to
protect_from_forgery with: :null_session
in ApplicationController
According to rails convention,
PUT is used for updating an existing resource
POST is used for creating a new resource
In rails 4, PUT has been changed to PATCH to avoid confusion.
posts GET /posts(.:format) {:action=>"index", :controller=>"posts"} POST /posts(.:format) {:action=>"create", :controller=>"posts"} new_post GET /posts/new(.:format) {:action=>"new", :controller=>"posts"} edit_post GET /posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"} post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"} PUT /posts/:id(.:format) {:action=>"update", :controller=>"posts"} DELETE /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"} 延伸閱讀:ihower - HTTP Verbs: 談 POST, PUT 和 PATCH 的應用