From: Robert Klemme Date: 2005-11-09T01:12:12+09:00 Subject: Re: Can ActiveRecord handle columns containing spaces? Anthony Hrvojic wrote: > Hello, > > 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 > > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base. rb:1545:in > `class_eval' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base. rb:1545:in > `class_eval' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base. rb:1545:in > `define_read_method' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base. rb:1530:in > `define_read_methods' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base. rb:1528:in > `each' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base. rb:1528:in > `define_read_methods' > c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.13.0/lib/active_record/base. rb:1478:in > `method_missing' > > Modifying the schema is probably not an option, so I'm hoping someone > may have a different approach. > > Thanks! Ypu might get away with creating a view with a different name for this column. IIRC you can insert into simple views such as create view foo(col1,col2) as select colx, coly from some_table It's generally not a good idea to have spaces in identifiers, even if they are column names - I guess you came to a similar conclusion already... :-) Kind regards robert