Easy rspec matchers

http://rspec.rubyforge.org/rspec/1.2.9/classes/Spec/Matchers.html

How to stop ActiveRecord putting attribute name in validation message

Use http://github.com/gumayunov/custom-err-msg/tree/master
Put a ^ at the start of the :message => option:
Non-base messages are prefixed with the attribute name as usual UNLESS they begin with ‘^’
in which case the attribute name is omitted.

Paperclip/ImageMagick image geometry specifiers

This can be a pain to find so here is the quick access version:
<width>x<height><specifier>
% Interpret width and height as a percentage of the current size.
! Resize to width and height exactly, loosing original aspect ratio.
< Resize only if the image is smaller than the geometry specification.
> Resize only if the image is greater than the [...]

Switching an ActiveRecord instance between STI classes

Sometimes you wish to convert one STI class to another, e.g. promote User to Administrator.
ActiveRecord::Base#becomes(Klass) returns an instance of the current record converted to the specified Klass, e.g.:

 
user = User.find_by_login("sam")
user.becomes(Administrator)

Note however that this does not change the type attribute of the instance, so you still have an additional step to do if you want this [...]

SV-Ruby Meetup, 2009-03-19

Yehuda Katz talked about Rails 3
Rails API should not change! It’s a mistake to change the API and the implementation at the same time (think Ruby 1.9 language and VM).
ORM Agnisticism
With for_for @obj, @obj can be an ActiveRecord, DataMapper, CouchDB, SimpleDB, Sequel object.  Two interfaces are now support for ORM objects, ActiveRecord/DataMapper style: errors, #each, [...]

ActiveRecord performance: validation and associations

If you have two models associated in some way, it is usual to add a validates_presence_of validator to ensure that the models are connected before saving. However, be aware that there are two ways of doing this with different performance ramifications:

class BlogEntry < ActiveRecord::Base
belongs_to :blog
validate_presence_of :blog
end

During validation, Validates_presence_of :blog causes ActiveRecord [...]

SVRoR Meetup, 2009/02/25

Ikai Lan, JRuby
Rails 2.2 is thread safe.  Threads are safe to use on the JVM.  Use threads and use their performance advantage.
Warble (from Sun – Charles Nutter et al) will package a complete Rails app for deployment on a Java App Server.
Lacks the ease of Passenger.
Lots of weird incompatibilities.  Timeout.  RubyIO.  Namespace issues.  Metaprogramming.  You [...]

Installing Ruby MySQL gem on Mac OS X Leopard

Thanks to this post, I discovered how to install the MySQL ruby gem on Mac OS X:
You must be using the x86 variant of MySQL, not x86_64, apparently.  Then:

sudo env ARCHFLAGS="-arch i386" gem install mysql — \
–with-mysql-dir=/usr/local/mysql –with-mysql-lib=/usr/local/mysql/lib \
–with-mysql-include=/usr/local/mysql/include

SvROR meetup, 2008/09/25

Jerry Luk, LinkedIn

Bumper Sticker RoR app: 17M users, 900M views/month
NewIN – show new linkedin uses on google maps / ?globe9?
LinkedIn mobile
LinkedIn iPhone App (not rails)
OpenSocial Sandbox (hackday project)
LinkedIn Polls using JRuby
Use Starling, Beanstalk looking at JMS

Emmet @ JustIn.tv

Website for live video on the Internet (Youtube but live!)
Wrote a caching reverse proxy in Python & Twisted.
Use Twisted [...]

Colon confuses custom_require (well an ancestor anyway)

I just started work on an existing project.  Rake would not run and kept dying with “no such file to load — ” exceptions in rubygems/custom_require.rb for files in a vendor/plugin/<foo>/lib folder.
It turns out that when I checked out the source from Subversion with:

svn co https://<hostname>:<portnumber>

It created a folder called <hostname>:<portnumber>
The colon in the path was confusing [...]