Wednesday, May 25, 2011

Translations / internationalization for active record error messages

Active Record will look for messages in this order:

activerecord.errors.models.admin.attributes.title.blank
activerecord.errors.models.admin.blank
activerecord.errors.models.user.attributes.title.blank
activerecord.errors.models.user.blank
activerecord.errors.messages.blank
errors.attributes.title.blank
errors.messages.blank

So example for validation for email format


# app/models/membership_requests.rb
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i

# config/locales/en.yml
en:
activerecord:
errors:
models:
membership_request:
attributes:
email:
invalid: "is not a valid email address"




reference: http://guides.rubyonrails.org/i18n.html

Thursday, May 19, 2011

Bit.ly API

Latest stable - v3.0
Rate limit - 5 concurrent users / IP address
http://code.google.com/p/bitly-api/wiki/ApiBestPractices
http://code.google.com/p/bitly-api/
http://code.google.com/p/bitly-api/wiki/ApiDocumentation
gem - https://github.com/philnash/bitly


gem install bitly
When you HTTParty, you must party hard!
Successfully installed crack-0.1.8
Successfully installed httparty-0.7.7
Successfully installed addressable-2.2.6
Successfully installed multipart-post-1.1.1
Successfully installed faraday-0.6.1
Successfully installed multi_json-1.0.2
Successfully installed oauth2-0.4.1
Successfully installed bitly-0.6.1
8 gems installed