如何在 Rails 3 的 ActionController::Metal 中包含 Responder?
我正在使用一个 Rails 3 控制器,该控制器的用途非常具体、有限,我所需要的就是让它响应 :json。
该截屏视频表示我的控制器可以从 ActionController::Metal 继承,然后只包含我需要的功能以加快速度: http://rubyonrails.org/screencasts/rails3/action-controller
当我的控制器看起来像这样:
class FoldersController < ActionController::Metal
respond_to :json
def all
respond_with Folder.all
end
end
我收到错误:
undefined method `respond_to' for FoldersController:Class
我尝试过包括 Responder、ActionController::Responder、ActionController::Metal::Responder,但它们都不起作用。我需要包含哪些内容才能获得此响应程序功能?
I'm working a Rails 3 controller that has a very specific, limited purpose, and all I need is for it to respond_to :json.
This screencast says my controller can inherit from ActionController::Metal, and then just include the functionality I need to make things faster:
http://rubyonrails.org/screencasts/rails3/action-controller
When my controller looks like this:
class FoldersController < ActionController::Metal
respond_to :json
def all
respond_with Folder.all
end
end
I get the error:
undefined method `respond_to' for FoldersController:Class
I've tried including Responder, ActionController::Responder, ActionController::Metal::Responder, but none of them work. What do I include to get this responder functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要包含更多类,而不仅仅是 Responder。这是我的 ApplicationController,但并非全部包含您可能需要的:
You need to include more classes, not only Responder. Here is my ApplicationController, but not all includes you may need:
ActionController::MimeResponds 看起来是路径。
ActionController::MimeResponds looks to be the path.