Notes posted by zubin
RSS feed
1 thank
Warning: prevents persistence but doesn't prevent setting
For example:
class Widget < ActiveRecord::Base attr_readonly :key end w = Widget.create! key: 'foo' w.update! key: 'bar' w.key #=> 'bar' w.reload.key #=> 'foo'

0 thanks
Beware: virtual attributes are ignored
Even though validations are called, virtual attributes are ignored.

4 thanks
How to specify :only_path when non-hash options
When passing in an object, as opposed to a hash, you can’t do this because url_for accepts one argument:
url_for(post, :only_path => true)
Instead, do this:
polymorphic_url(object, :routing_type => :path)

8 thanks
case-insensitive uniqueness
For case-insensitive uniqueness:
validate :username, :uniqueness => {:case_sensitive => false}

4 thanks
When scripts don't end in .js
For example, Google Custom Search’s URL is http://www.google.com/jsapi
It’s an ugly hack, but works:
= javascript_include_tag('http://www.google.com/jsapi').sub('.js', '')