# Hyphens in column names

**URL:** <https://www.ruby-forum.com/t/hyphens-in-column-names/48337>\
**Category:** Rails\
**Created:** [November 19, 2005, 12:52am UTC](https://www.ruby-forum.com/t/hyphens-in-column-names/48337 "2005-11-19T00:52:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [November 19, 2005, 12:52am UTC](https://www.ruby-forum.com/t/hyphens-in-column-names/48337/1 "2005-11-19T00:52:46Z")

</div>

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?’ %\> |

---

<div class="post-metadata">

**Author:** ![snacktime](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@snacktime](https://www.ruby-forum.com/u/snacktime)\
**Post date:** [November 19, 2005, 12:58am UTC](https://www.ruby-forum.com/t/hyphens-in-column-names/48337/2 "2005-11-19T00:58:47Z")

</div>

-----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-----
