`
RunUpwind
  • 浏览: 90438 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

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'

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics