Skip to content

Instantly share code, notes, and snippets.

@moro
Created June 6, 2011 06:11
Show Gist options
  • Save moro/1009814 to your computer and use it in GitHub Desktop.
Save moro/1009814 to your computer and use it in GitHub Desktop.
define column default in app/models/*.rb
class Person < ActiveRecord::Base
def self.column_default_values(defs)
defs.each do |cname, value|
columns.detect{|c| c.name.to_sym == cname.to_sym }.instance_variable_set('@default', value)
end
end
column_default_values(name: 'hibariya')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment