let total : Int=0// 強制宣告total為Int let taxRate =0.13// 一般的宣告方式
但如果沒特殊理由,使用預設的宣告方式以加強可讀性
Array and Dictionaries
1 2 3
let taxRate = [0.15, 0.18, 0.20] // array let emptyArray = [String]() // create an empty array with String type var arr = [[Int]]() // 2 dimensional array of arrays of Ints
Rails.application.routes.draw do resources :posts# http://your-domain/posts constraints subdomain:'api'do resources :contents# http://api.your-domain/contents end end
為了讓controller的目錄更有組織性,可以加上namespace
routes.rb
1 2 3 4 5 6 7 8 9
Rails.application.routes.draw do resources :posts constraints subdomain:'api'do namespace :apido resources :contents# http://api.your-domain/api/contents end end end
雖然controller目錄變乾淨,但URL卻多出個api/contents。 加入path
routes.rb
1 2 3 4 5 6 7 8 9
Rails.application.routes.draw do resources :posts constraints subdomain:'api'do namespace :api, path:'/'do resources :contents# http://api.your-domain/contents end end end
最後用一行搞定
routes.rb
1 2 3 4 5 6 7
Rails.application.routes.draw do resources :posts namespace :api, path:'/', constraints: { subdomain:'api' } do resources :contents end end
<script src="//maps.google.com/maps/api/js?v=3.18&sensor=false&client=&key=&libraries=geometry&language=&hl=®ion="></script> <script src="//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js"></script> <script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js' type='text/javascript'></script> <!-- only if you need custom infoboxes -->