Notes posted by zubin
RSS feed
zubin -
September 9, 2015
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'
zubin -
November 30, 2012
0 thanks
Beware: virtual attributes are ignored
Even though validations are called, virtual attributes are ignored.
zubin -
March 25, 2011
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)
zubin -
February 21, 2011 - (>= v3.0.0)
8 thanks
case-insensitive uniqueness
For case-insensitive uniqueness:
validate :username, :uniqueness => {:case_sensitive => false}
zubin -
July 20, 2010
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', '')