to_include.jbg
来自「ruby on rails web敏捷开发之路第二版 源代码」· JBG 代码 · 共 65 行
JBG
65 行
module ActiveRecord module Validations module ClassMethods def validates_as_credit_card(*attr_names) configuration = { :message => "must be a valid credit card number.", :on => :save, :with => nil } configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash) validates_each(attr_names, configuration) do |record, attr_name, value| if(value != nil) record.errors.add(attr_name, configuration[:message]) unless value.creditcard? && value.creditcard_type == record.send(configuration[:card_type]) end end end def validates_not_blacklist(*attr_names) configuration = { :message => 'not a valid value.', :on => :save, :with => nil } configuration.update(attr_names.pop) if attr_names.last.is_a?(Hash) validates_each(attr_names, configuration) do |record, attr_name, value| if(value != nil) record.errors.add(attr_name, configuration[:message]) unless !in_blacklist?(value) end end end end end class Base def to_csv(options = {}) options[:except] = Array(options[:except]) << self.class.inheritance_column unless options[:only] # skip type column only_or_except = { :only => options[:only], :except => options[:except] } attributes_for_csv = attributes(only_or_except) results = "" results += '"' + attributes_for_csv.keys.join('","') + '"' + "\n" if(options[:include_header] || options[:only_header]) return results if(options[:only_header]) results += '"' + attributes_for_csv.values.join('","') + '"' return results end endendmodule ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module Array #:nodoc: module Conversions def to_csv(options = {}) results = "" if(options[:include_header]) options[:only_header] = true results += self[0].to_csv(options) end options[:only_header] = false options[:include_header] = false self.each do |record| results += record.to_csv(options) + "\n" end return results end end end endend
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?