ruby-on-rails – Rails 3上的继承资源…响应者

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Rails 3上的继承资源…响应者前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚刚开始为我正在构建的应用程序使用InheritedResources,当我查看它的 Github页面时,它说它已被弃用,我应该使用Responders.

我是InheritedResources和Responders的新手,所以我很困惑,当我从文档中看到的是FlashResponders和HTTPCacheResponders时,我怎样才能从Responders获得我在InheritedResources中获得的内容(完整的REST动作库“模板”代码)?

我也看过这个:

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

这是否意味着我不再需要“REST模板代码”?

解决方法

response_with(内置于Rails中)与响应者gem的组合使得InheritedResources不再使用.

请查看this blog post以获得有关如何使用respond_with创建RESTful控制器的出色解释和演示.大多数控制器动作都减少为单行代码;使用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.”

如果要自动执行控制器操作的任何其他部分(例如,设置闪存消息),响应者将发挥作用.

更新:对于下面询问破坏行动的评论

def destroy
  record = Record.find(params[:id])
  flash[:notice] = "The record has been destroyed successfully" if record.destroy
  respond_with record
end
原文链接:https://www.f2er.com/ruby/264943.html

猜你在找的Ruby相关文章