ITeye博客

rails中如何添加自定义的请求格式

RunUpwind · 2011-06-22 11:28 · ruby on rails · 编程语言 · Markdown

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'

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。