【发布时间】:2012-07-14 21:44:04
【问题描述】:
场景
我有一个 Sinatra 应用程序
我有一个基于某个命名路径获取文章的路由
# 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/:today.json" 而不是"/frontpage/:type",是否可以保留这条路线"/frontpage/:type" 并显示.json 页面?
或
专门为 JSON 请求创建单独的路由会更好吗?
【问题讨论】:
标签: ruby json activerecord routes sinatra