简体   繁体   English

Rails 3上的继承资源...响应者

[英]Inherited Resources Deperecated on Rails 3…Responders

I have just started using InheritedResources for an application I'm building and when I looked at its Github page, it says it's deprecated, and that I should instead use Responders. 我刚刚开始为我正在构建的应用程序使用InheritedResources,当我查看它的Github页面时,它说它已被弃用,我应该使用Responders。

I am new to InheritedResources and Responders so I am confused, how can I get from Responders what I get in InheritedResources (complete REST actions base "template" code) when all I see from the documentation are FlashResponders and HTTPCacheResponders? 我是InheritedResources和Responders的新手,所以我很困惑,当我从文档中看到的是FlashResponders和HTTPCacheResponders时,我怎样才能从Responders获得我在InheritedResources中获得的内容(完整的REST操作基础“模板”代码)?

I have also taken a look at this one: 我也看过这个:

http://blog.plataformatec.com.br/tag/inherited_resources/ http://blog.plataformatec.com.br/tag/inherited_resources/

so does that mean that no more "REST template code" for me? 这是否意味着我不再需要“REST模板代码”?

The combination of respond_with (which is built in to Rails) in conjunction with the responders gem makes InheritedResources deprecated. respond_with (内置于Rails中)与responders gem的组合使得InheritedResources不再使用。

Please have a look at this blog post for an excellent explanation and demonstration of how to create a RESTful controller using respond_with . 请查看此博客文章 ,了解如何使用respond_with创建RESTful控制器的出色解释和演示。 Most of the controller actions are reduced to single lines of code; 大多数控制器动作都减少为单行代码; with InheritedResources it was possible to have a controller with no code (because it was hidden away in the gem), but Jose Valim (creator of InheritedResources) thought this was too obfuscated as per his quote: 使用InheritedResources可能有一个没有代码的控制器(因为它隐藏在gem中),但是Jose Valim(InheritedResources的创建者)认为这根据他的引用过于模糊:

"I have found that the responders abstraction and custom Rails generators offer the perfect balance between hiding and showing too much logic." “我发现响应者的抽象和自定义Rails生成器在隐藏和显示太多逻辑之间提供了完美的平衡。”

The responders come into play if you want to automate any other parts of the controller action, for example, setting the flash messages. 如果要自动执行控制器操作的任何其他部分(例如,设置闪存消息), responders将发挥作用。


UPDATE: For the commenter below who asked about the destroy action 更新:对于下面询问destroy行动的评论者

def destroy
  record = Record.find(params[:id])
  flash[:notice] = "The record has been destroyed successfully" if record.destroy
  respond_with record
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM