rails默认request的格式是 text/html. 同时还支持 xml 和 json.
如果要添加一个格式如.api, 访问路径:http://..../login.api, 该如何做?
参照:http://stackoverflow.com/questions/2456219/add-a-custom-format-in-rails-that-will-work-with-respond-to
# add in Environment.rb
Mime::Type.register "api/json", :api
在controller中,可以用request.format 取得值为 'api/json'
本文介绍如何在 Rails 应用中添加自定义的 API 格式支持,通过注册新的 MIME 类型并展示如何在控制器中使用 request.format 获取请求格式。
1680

被折叠的 条评论
为什么被折叠?



