# ActiveRecord dumb on capitalized acronyms?

**URL:** <https://www.ruby-forum.com/t/activerecord-dumb-on-capitalized-acronyms/49955>\
**Category:** Rails\
**Created:** [December 11, 2005, 12:12am UTC](https://www.ruby-forum.com/t/activerecord-dumb-on-capitalized-acronyms/49955 "2005-12-11T00:12:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [December 11, 2005, 12:12am UTC](https://www.ruby-forum.com/t/activerecord-dumb-on-capitalized-acronyms/49955/1 "2005-12-11T00:12:37Z")

</div>

Hi,

I just ran into an unitialized contstant error for ‘Mp3’ with rails.  
When I generated my model from the commandline, I used something like…  
‘ruby script/generate model MP3’ and it created mp3.rb with an AR class  
called ‘MP3’, so I figured it was ok, but now this doesn’t seem to work.

Going in and changing all references of the ‘MP3’ class to ‘Mp3’ seemed  
to fix it, but it doesn’t look as nice since it’s supposed to be an  
acronym. Is there any way I can make it respect those capitalization  
rules? I haven’t gotten this far yet, but will I most likely run into  
the same problem with a ‘CD’ class?

I am using InstantRails (thanks Curt!) updated to 1.0 RC5 gems. The  
actual line that seems to have caused the problem was:

track.mp3 = MP3.new( :filename =\> ‘blah’ )

In the above, Track has\_one :mp3 and MP3 belongs\_to :track

Just for fun I tried ‘track.m\_p3’ too and it didn’t work. Tried to  
google for a solution since I’m sure I’m not the first, but I came up  
empty handed.

Thanks in advance!

-Pawel

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [December 11, 2005, 3:17pm UTC](https://www.ruby-forum.com/t/activerecord-dumb-on-capitalized-acronyms/49955/2 "2005-12-11T15:17:32Z")

</div>

I dont think this is an AR issue, but just a general Ruby one. In  
general all cap items are considered to be constants. Did you get an  
error message? If so could you post it to confirm or deny this?

-Nick

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [December 11, 2005, 9:18pm UTC](https://www.ruby-forum.com/t/activerecord-dumb-on-capitalized-acronyms/49955/3 "2005-12-11T21:18:11Z")

</div>

On Dec 11, 2005, at 9:15 AM, Nick S. wrote:

> I dont think this is an AR issue, but just a general Ruby one. In  
> general all cap items are considered to be constants. Did you get an  
> error message? If so could you post it to confirm or deny this?
> 
> -Nick

No, it’s a Rails issue. The issue is going from MP3 to mp3 is easy,  
but going the other way is much less robust.

Consider a more enlightening example, say you’ve got a class RSSFeed

> > ‘RSSFeed’.tableize  
> > =\> “rss\_feeds”

That’s very easy, a simple rule saying if there are multiple capital  
letters in a row, it’s a possible acronym, separate at the last one.

The problem is going the other way:

> > ‘rss\_feeds’.classify  
> > =\> “RssFeed”

Woops, there’s no reasonable way to know that ‘rss’ should be an acronym  
rather than the word Rss.

You could likely hack in some special magic to make it work for a given  
case, but it’s really easiest to just accept stuff like RssFeed and Mp3.

It’s not perfect, but it’s also a difficult problem to solve with a  
practical solution (ie not keeping a giant list of all possible  
acronyms).

–  
Scott B.  
Lunchbox Software  
[http://lunchboxsoftware.com](http://lunchboxsoftware.com)  
[http://lunchroom.lunchboxsoftware.com](http://lunchroom.lunchboxsoftware.com)  
[http://rubyi.st](http://rubyi.st)

---

<div class="post-metadata">

**Author:** ![makenai](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8797f3/32.png) [@makenai](https://www.ruby-forum.com/u/makenai)\
**Post date:** [December 11, 2005, 10:53pm UTC](https://www.ruby-forum.com/t/activerecord-dumb-on-capitalized-acronyms/49955/4 "2005-12-11T22:53:49Z")

</div>

Thanks for the replies Nick and Scott,

> No, it’s a Rails issue. The issue is going from MP3 to mp3 is easy,  
> but going the other way is much less robust.

Yeah, I figured ruby would be OK with it since we have a YAML module and  
probably many other examples.

> Woops, there’s no reasonable way to know that ‘rss’ should be an acronym  
> rather than the word Rss.
> 
> You could likely hack in some special magic to make it work for a given  
> case, but it’s really easiest to just accept stuff like RssFeed and Mp3.
> 
> It’s not perfect, but it’s also a difficult problem to solve with a  
> practical solution (ie not keeping a giant list of all possible  
> acronyms).

That makes sense now that you explain it that way. Though I would think  
it would be possible to generate some sort of a lookup table at model  
generation time or something - especially since the generate script  
honors the capitalization given on the command line. I’d think that  
(knowing it won’t work correctly up front) there would at least be some  
automagical capitalization (or just a round trip conversion of MP3 class  
-\> mp3 attribute -\> Mp3 class) fix from MP3 -\> Mp3 in the same graceful  
way that reserved words are handled.

Do either of those sound like a reasonable solution to anyone?

-Pawel
