Notes posted by vighnesh1987

RSS feed
May 31, 2013
2 thanks

Do not mistakenly use serialize like other similar directives - attr_accessible, attr_accessor

serialize seems very similar to other directives that work on attributes such as attr_accessible. One may mistakenly assume that serialize can take a list of attributes. For eg:

class Tuk < ActiveRecord::Base
  attr_accessible :foo, :bar
  serialize :foo, :bar

This may lead to a cryptic error. Eg.

puts !Tuk.first.foo.nil?


NoMethodError at /file:location undefined method `new' for :bar:Symbol

This is because it tries to parse the YAML string stored in foo as an instance of :bar.