Created
May 27, 2010 14:51
-
-
Save stuartc/415887 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Used to get around the pesky camel case dbs such as MSSQL when u can't change them. | |
# Adds reader and writer methods for the columns. | |
# add 'fix_camelcase_columns' into your model. | |
class ActiveRecord::Base | |
def self.fix_camelcase_columns | |
define_method :after_find do | |
self.class.columns.each do |column| | |
self.instance_eval("def #{column.name.underscore}; self.#{column.name}; end;") | |
self.instance_eval("def #{column.name.underscore}=(x); self.#{column.name}=x; end;") | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment