如何从控制器 (Rails) 获取处理类型
当 HTTP 请求进入服务器时(在本例中我运行的是默认为 webrick 的rails s),消息看起来像这样:
Started POST "/cards" for 127.0.0.1 at 2011-11-05 15:04:29 -0400
Processing by CardsController#create as JS
我想知道在这种情况下如何获取值 JS,或 HTML。抱歉,我不能更明确,我不确定该值叫什么。有人有什么想法吗?
谢谢
When an HTTP request comes into the server (in this case I'm running rails s
which defaults to webrick) the message looks something like:
Started POST "/cards" for 127.0.0.1 at 2011-11-05 15:04:29 -0400
Processing by CardsController#create as JS
I'm wondering how to get the value JS in this case, or HTML. Sorry I can't be more explicit, I'm not sure what that value is called. Anyone have any ideas?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 request.format 来获取格式。对于 JS 请求,它将返回“text/javascript”,对于 HTML 请求将返回“text/html”,对于 JSON 请求将返回“application/json”等。
另外,您通常会在
respond_to
块中使用它:You can use
request.format
to get the format. It'll return "text/javascript" for JS requests, "text/html" for HTML, "application/json" for JSON, etc.Also, you would typically use this in a
respond_to
block: