Recent good notes

class ActiveRecord::Base# normal find_each does not use given order but uses id ascdef self.find_each_with_order(options={})raise"offset is not yet supported"ifoptions[:offset]page=1limit=options[:limit]||1000loopdooffset=(page-1)*limitbatch=find(:all,options.merge(:limit=>limit,:offset=>offset))page+=1batch.each{|x|yieldx}breakifbatch.size<limitendendend

As is the case with the before_validation
and before_save
callbacks, returning false will break the callback chain. For
example, the expire_cache_id method will not run if Rails.cache.expire
returns false (as it will if the key is not cached with memcache).

Before Rails 2.2 you could globally customize
the default validation error messages by changing
AR::Base.default_error_messages. The messages have now been moved
to i18n, so to customize them in 2.2 and up, just create a
locales/ folder in your config/ folder, copy
activerecord/lib/active_record/locale/en.yml (in Rails source) to config/locales/en.yml,
and then change the strings inside. As szeryf indicated below, the
strings of interest are activerecord.errors.messages.

So far so good you might think. However, something you might not
have expected is that the variable has now also changed in class A:

pA.foo# => "bar"

This is in my opinion almost never what you’d want. More probable is that
you’d want the individual class instance to have an accessor. (Remember
classes are objects in Ruby). I do the
following in regular Ruby:

As you can see, this returns nil when a value hasn’t explicitly
been set yet on the new class instance. If you’d like to have inheritance
without messing with the superclasses variables, have a look at
ActiveSupport’s class_inheritable_accessor, which does the same as I just
explained, but creates a clone of the object and assigns it to the subclass
whenever a class is inherited.

What I’d normally do in Ruby to fix
the issue of it returning nil is to create the accessor manually
and have it set the instance variable to the default if it’s
nil:

Unlike the save method, you
can’t pass false to update_attributes to
tell it to skip validation. Should you wish to do this (consider carefully
if this is wise) update the
attributes explicitly
then call save and pass false:

If you’d like to specify a respond_to
only for 1 or a few formats and render something else for all other
formats, eg: (action.rss returns a feed but action.html or action.js should
just render 404), use format.all: