# Hyphen on columns name.. help

**URL:** <https://www.ruby-forum.com/t/hyphen-on-columns-name-help/134793>\
**Category:** Rails\
**Created:** [April 15, 2008, 6:28am UTC](https://www.ruby-forum.com/t/hyphen-on-columns-name-help/134793 "2008-04-15T06:28:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 15, 2008, 6:28am UTC](https://www.ruby-forum.com/t/hyphen-on-columns-name-help/134793/1 "2008-04-15T06:28:31Z")

</div>

I have a issue that I can’t seen to fix… I search all over… and a lot  
about how to work with legacy _table_ names but nothing about _column_  
names…  
this will not work because of the hyphen:  
@vcards = Vcard.find(:all, :select =\> “collection-owner”)

this below will work but give me a lot of junk…!!  
@vcards = Vcard.find(:all, :select =\> “`collection-owner`”)

as well this:  
@vcards = Vcard.find(:all, :select =\> “‘collection-owner’”)

but when I call this from a:  
\<%= render :blablabla, :collection =\> @vcards %\>

and in the \_blablabla.rhtml

**\<%= @vcards -%\>**

I will just get ##### and more garbage…  
same when I do with console

can anyone tell me how can I work with column names with “-”  
hyphens…??? this is frustrating me… I loved rails but this is  
starting to annoy me…  
because I understand that tables should be created such a way but there  
should be options to work  
with legacy tables and not only table names and indexes but also column  
names… I have not found anything so far  
and trust me I HAVE LOOK and I am not the best using Google but my last  
hope before I finish this project on PHP is this call.

HELP!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 15, 2008, 7:04am UTC](https://www.ruby-forum.com/t/hyphen-on-columns-name-help/134793/2 "2008-04-15T07:04:45Z")

</div>

The #### is just ruby printing out an object reference.

it’s not garbage. it’s ruby’s description of the object.

What you want is

\<%= @vcards.to\_yaml %\> or something else that will render them in a  
different way.

Most likely you’ll ACTUALLY want to traverse all the elements of that  
array (@vcards) and print out items from it

\<% for item in @vcards -%\>  
\<%= item.name %\>  
\<% end -%\>

assuming “name” is one of the attributes on your vcard object.

You need to learn to walk before you can run. You seem to be trying to  
jump WAY into the deep end. Why not just build a simple small rails  
app that you control first and then try for your legacy table one that  
you’re using?

Julian.

Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)  
VIDEO #4 coming soon!  
[http://sensei.zenunit.com/](http://sensei.zenunit.com/)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 15, 2008, 9:01am UTC](https://www.ruby-forum.com/t/hyphen-on-columns-name-help/134793/3 "2008-04-15T09:01:26Z")

</div>

Julian L. wrote:

> Most likely you’ll ACTUALLY want to traverse all the elements of that  
> array (@vcards) and print out items from it
> 
> \<% for item in @vcards -%\>  
> \<%= item.name %\>  
> \<% end -%\>

## Hi, hmm but I already know this… my issue is not the way I do it… (I try many ways) it just happen for me to have send the last way I was trying… the issue is the hyphen in the column name… no matter what way I use as long I can’t get rails to ignore the hyphen somehow or something is not going to work…

## for item in @vcards item.collection-owner end

NoMethodError: undefined method `collection’

the hyphen is my issue.

> assuming “name” is one of the attributes on your vcard object.

the problem is that the attributes is the one with the hyphen…

item.attributes  
=\> {“collection-owner”=\>“removed\_email\_address@domain.invalid”}

> You need to learn to walk before you can run. You seem to be trying to  
> jump WAY into the deep end. Why not just build a simple small rails  
> app that you control first and then try for your legacy table one that  
> you’re using?
> 
> Julian.

LOL but then is boring 😉 if it was not because of the incompatibility  
column name I will have no problem.

Thanks.

> > lot  
> > @vcards = Vcard.find(:all, :select =\> “‘collection-owner’”)  
> > same when I do with console  
> > and trust me I HAVE LOOK and I am not the best using Google but my
> 
> >

–  
A Spectre is haunting multinational capitalism–the spectre of free  
information.  
All the powers of ``globalism’’ have entered into an unholy alliance to  
exorcize this spectre:  
Microsoft and Disney, the World Trade Organization, the United States  
Congress and the European Commission.  
Eben Moglen from the FSF.  
[http://emoglen.law.columbia.edu/publications/dcm.html](http://emoglen.law.columbia.edu/publications/dcm.html)

Solidarity:  
[http://www.dailyradical.org](http://www.dailyradical.org)  
[http://www.diarioradical.org](http://www.diarioradical.org)  
[http://www.spboston.org](http://www.spboston.org)

> **[MESSIPOKER - Situs Judi Slot Online Dan Toto 4D Togel Terbaru](https://binaryfreedom.info/)**
>
> MESSIPOKER ialah situs judi slot online terbaik dan toto 4D online terpercaya no 1 di Indonesia yang siap memberikan pelayanan maksimal kepada anda.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 15, 2008, 9:03am UTC](https://www.ruby-forum.com/t/hyphen-on-columns-name-help/134793/4 "2008-04-15T09:03:46Z")

</div>

On Apr 15, 8:00 am, rek2 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi, hmm but I already know this… my issue is not the way I do it… (I  
> try many ways) it just happen for me to  
> have send the last way I was trying… the issue is the hyphen in the  
> column name…  
> no matter what way I use as long I can’t get rails to ignore the hyphen

Write your own accessors:  
def owner  
self[:“collection-owner”]  
end

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [April 15, 2008, 9:07am UTC](https://www.ruby-forum.com/t/hyphen-on-columns-name-help/134793/5 "2008-04-15T09:07:54Z")

</div>

> Write your own accessors:  
> def owner  
> self[:“collection-owner”]  
> end

Thanks!!! this is something I was looking for…  
I am going to research the topic thank you.
