19th
History Blog Meme
history 1000 | awk ‘{a[$2]++}END{for(i in a){print a[i] ” ” i}}’ | sort -rn | head95 cd 72 ls 52 svn 49 rake 27 exit 24 p 22 sudo 20 mimi 16 cap 15 gitvia objo
95 cd 72 ls 52 svn 49 rake 27 exit 24 p 22 sudo 20 mimi 16 cap 15 gitvia objo
module ActsAsFerret
module InstanceMethods
# Overriding these so we don't hit DRb
def ferret_create; true; end
def ferret_update; true; end
def ferret_destroy; true; end
end
end
Find: (,"[^"]+)\n([^"]+") Replace: $1 $2This will need to be run repeatedly until it doesn’t match anymore because it only removes one newline from a field at a time and some fields may have multiple newlines.
ActiveRecord::Base.logger = Logger.new(SOME_LOG_NAME) Sinatra::Environment.prepare_loggers(ActiveRecord::Base.logger)
Sometimes you need to compare an attribute of an in-memory ActiveRecord instance against its attribute in the database. The way I usually do that is to grab a fresh instance from the database like this:
class Something < ActiveRecord::Base
def previous(attribute)
self.class.find(id)[attribute]
end
end
That worked just fine in Rails 1.2. But Rails 2.0 has request-scoped query caching enabled by default, meaning that if you have already executed the same SQL that is generated by find(id), you’re going to get the exact same instance back from that call to find. This makes it impossible to compare in-memory attributes against attributes stored in the database.
The solution is to use ActiveRecord’s uncache method. This is a class method, so you’ll need to grab your class to call it like this:
class Something < ActiveRecord::Base
def previous(attribute)
self.class.uncached { self.class.find(id)[attribute] }
end
end
If you ever need to use ActiveRecord’s has_many with finder_sql, remember that the key to finder_sql is that the String get eval’d in the context of the ActiveRecord instance rather than the ActiveRecord class. So make sure you use single quotes! This prevents the String from being interpolated too soon.
Do this:
has_many :foos,
:finder_sql => 'select ... where some_id=#{id}'
Not this:
has_many :foos,
:finder_sql => "select ... where some_id=#{id}"
In the former case, the #{id} will be the id of the ActiveRecord instance. In the latter case, the #{id} will be the id of the ActiveRecord class.