Ruby on Rails的:延长的ActiveRecord ::错误

编程入门 行业动态 更新时间:2024-10-28 19:19:06
本文介绍了Ruby on Rails的:延长的ActiveRecord ::错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Ruby on Rails的,哪里有人所说的code这段代码中的http://依据。 github/376389 ?我想的ActiveRecord ::错误延伸与code,它是可有这样我就可以合并的错误消息。

这是不是对的ApplicationController?或LIB?

从github

粘贴

从dev.rubyonrails/attachment/ticket/11394/merge_bang_errors.patch#猴子补丁收集 模块的ActiveRecord   类错误     DEF合并!(错误,选项= {})       fields_to_merge =如果只=选项[:只有]         只要       ELSIF除=选项[:除了]         除了= [除外],除非except.is_a?(阵列)         except.map(安培;:to_sym)!         errors.entries.map(安培;:第一)。选择做|视|           !except.include?(field.to_sym)         结束       其他         errors.entries.map(安培;:第一)       结束       fields_to_merge = [fields_to_merge除非fields_to_merge.is_a?(阵列)       fields_to_merge.map(安培;:to_sym)!       errors.entries.each做|现场,味精|         如果fields_to_merge.include加场,味精?(field.to_sym)       结束     结束   结束 结束

解决方案

您可以直接丢弃到你的初始化目录中的任何ruby文件(创建一个新的,名称任何你想要的)。轨运行的所有文件有每次启动时的时间,并会延长错误在那个时候。

In Ruby on Rails, where does one put the code from this snippet in gist.github/376389? I want to extend ActiveRecord::Errors with the code that's available there so I can merge error messages.

Is this something for ApplicationController? or for lib?

Paste from github

# monkey patch gleaned from dev.rubyonrails/attachment/ticket/11394/merge_bang_errors.patch module ActiveRecord class Errors def merge!(errors, options={}) fields_to_merge = if only=options[:only] only elsif except=options[:except] except = [except] unless except.is_a?(Array) except.map!(&:to_sym) errors.entries.map(&:first).select do |field| !except.include?(field.to_sym) end else errors.entries.map(&:first) end fields_to_merge = [fields_to_merge] unless fields_to_merge.is_a?(Array) fields_to_merge.map!(&:to_sym) errors.entries.each do |field, msg| add field, msg if fields_to_merge.include?(field.to_sym) end end end end

解决方案

You can just drop that into any ruby file in your initializers directory (create a new one, name it whatever you want). Rails runs all of the files in there every time it is booted, and will extend Errors at that time.

更多推荐

Ruby on Rails的:延长的ActiveRecord ::错误

本文发布于:2023-10-27 06:41:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   Ruby   Rails   ActiveRecord

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!