Hyphens in column names

It seems that rails doesn’t like hyphens in column names. This is
just one of several that I get the same error message on. Is there a
way to use hyphens in column names? This table gets written out to a
text configuration file for an application that needs the field names
with hyphens, so if I use an underscore in rails I just have to write
extra code to reformat the field names when exporting the data to the
text file.

(eval):1:in `class_eval’: compile error
(eval):1: syntax error
def announce-frequency; raise NoMethodError, ‘missing attribute:
announce-frequency’, caller unless
@attributes.has_key?(‘announce-frequency’);
@attributes[‘announce-frequency’]; end
^
(eval):1: syntax error
def announce-frequency; raise NoMethodError, ‘missing attribute:
announce-frequency’, caller unless
@attributes.has_key?(‘announce-frequency’);
@attributes[‘announce-frequency’]; end

                                    ^

Extracted source (around line #13): 10:


11: <% for astqueue in @astqueues %>
12:
13:
14:
15:
16:
<%= astqueue.send(“name”) %> <%= link_to ‘Edit’, :action => ‘edit’, :id =>
astqueue %>
<%= link_to ‘Destroy’, { :action => ‘destroy’,
:id => astqueue }, :confirm => ‘Are you sure?’ %>

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 18, 2005, at 3:51 PM, snacktime wrote:

It seems that rails doesn’t like hyphens in column names.

Active Record expects to make methods with the same name as the
database column. Therefore, database column naming but agree with
Ruby method naming.

If you wish, you may turn off autogenerated reader methods:
ActiveRecord::Base.generate_read_methods = false

And define your own “wrapper” methods with underscores (or whatever):
def my_clean_attribute
read_attribute(‘my-clean-attribute’)
end

jeremy
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (Darwin)

iD8DBQFDfmopAQHALep9HFYRApixAJwOObhbLVQSCKxCXsZom9o31OJIqwCgzpdg
bZn1hb01EK2XlzK62NS5uvU=
=HRC4
-----END PGP SIGNATURE-----