rails中怎么添加自定义的请求格式
rails中如何添加自定义的请求格式
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'