方案
我有一個西納特拉應用
我有一個基於一定的命名路徑西納特拉應用JSON和路線
# Get Articles for a certain time period
get '/frontpage/:type' do
case params[:type]
when "today"
@news = Article.find(...)
when "yesterday"
@news = Article.find(...)
when "week-ago"
@news = Article.find(...)
when "month-ago"
@news = Article.find(...)
else
not_found
end
erb :frontpage
end
問題
上取物品的路線是否有可能保持這條路線"/frontpage/:type"
,並顯示一個.json頁面,如果有人要求"/frontpage/:today.json"
而不是"/frontpage/:type"
?
或
是否更好地爲JSON請求創建單獨的路由?
這是一個很好的例子。我一直認爲這將是一種方法。從來沒有考慮過像這樣分手。 – alenm 2012-07-16 20:13:33