方案
我有一个西纳特拉应用
我有一个基于一定的命名路径西纳特拉应用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