加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 23:14:40 所属栏目:百科 来源:网络整理
导读:我刚刚开始为我正在构建的应用程序使用InheritedResources,当我查看它的 Github页面时,它说它已被弃用,我应该使用Responders. 我是InheritedResources和Responders的新手,所以我很困惑,当我从文档中看到的是FlashResponders和HTTPCacheResponders时,我怎样才
我刚刚开始为我正在构建的应用程序使用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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读