2009
03.29

If you want to write your own custom validation – Say each part of the name should be only 20 characters long – here is how you can do it. Add a callback called validate in the model and here is how it looks

def validate
	if name.split.any?{|w| w.length > 20}
		errors.add(:name, "cannot have name more than 20 consecutive characters")
	end
end
2009
03.05

While using Net::FTP inside a firewall. Make sure to use the passive option else the get data functions might freeze because the firewall does not allow incoming connections.

Here is how the ftp code will look

  ftp = Net::FTP.new('ftp.netlab.co.jp')
  ftp.login
  ftp.passive = true
  files = ftp.chdir('pub/lang/ruby/contrib')
  files = ftp.list('n*')
  ftp.getbinaryfile('nif.rb-0.91.gz', 'nif.gz', 1024)
  ftp.close
2009
03.03

#: ruby script/console
>> include ActionController::UrlWriter
And from here all of our route helpers (*_path and *_url) are available from the console.

>> users_path
=> “/users”

http://www.infinitecube.com/?p=5=1

2009
03.01

http://dizzy.co.uk/ruby_on_rails/cheatsheets/active-record-validation-errors#full_messages