From: Jeremy Kemper Date: 2005-11-09T04:37:16+09:00 Subject: Re: Can ActiveRecord handle columns containing spaces? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Nov 8, 2005, at 8:02 AM, Anthony Hrvojic wrote: > I'm using Rails 0.14.3 (upgraded this morning in case it would solve > this) with an existing SQL Server database and I'm running into a > problem where one of my models fails to instantiate seemingly due to a > single column containing a space in its name, which I guess interferes > with dynamic attribute generation. > > The exception I get in my browser looks something like this: > > (eval):1:in `class_eval': compile error > (eval):1: formal argument cannot be a constant > def Spaced Column; raise NoMethodError, 'missing attribute: Spaced > Column', caller unless @attributes.has_key?('Spaced Column'); > (v=@attributes['Spaced Column']) && > ActiveRecord::ConnectionAdapters::ColumnWithIdentity.string_to_time > (v); > end Anthony, you may turn off reader method generation if you'd like this to work directly, though you'll lose its substantial speed boost. In config/environment.rb config.active_record.generate_read_methods = false Then you may wrap the offending column with Ruby-friendly method names: def sane_column read_attribute('Spaced Column') end def sane_column=(value) write_attribute('Spaced Column', value) end jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDcP5nAQHALep9HFYRAj1LAKDPVbgecpiDPduT3Hq1dSKOJKMfVQCgjGej wxO+TsOvQcUKRu8BeSArjbk= =E41D -----END PGP SIGNATURE-----