ruby 1.9.3 和 rails 3.2.14 发现个小问题。 用
Model.where(:enabled => 1) #可以找到记录 each_record_in_scope do |a| next if a.enabled!=1 end #记录会全部被next掉
打开 irb 也测试了， a.enabled != 1 为 true。
The Active Record connection adapters, classes that implement behavior specific to databases, fetch results as strings and Rails takes care of converting them to other datatypes if necessary, based on the type of the database column. For instance, integer types are cast to instances of Ruby’s Fixnum class, and so on. Even if you’re working with a new instance of an Active Record object, and have passed in constructor values as strings, they will be typecast to their proper type when you try to access those values as attributes. Sometimes you want to be able to read (or manipulate) the raw attribute data without having the column determined typecast run its course first, and that can be done by using the
attribute_before_type_castaccessors that are automatically created in your model.