Ruby on Rails having problems with table column names
JUN
15
2006
I was working on a project for work today that invloved the client be able to enter customer testimonials into a database to be displayed randomly on each site page. I named the table quotes and it had three columns: id, person, and quote. I made id an integer and quote and person were both varchars. Everything worked fine with this configuration.
After some testing, I discovered that a varchar wasn't the best type for the quote because it didn't have enough room for the longer testimonials. Like a good Rails developer, I wrote a migration script to change the quote column to be text instead of varchar. Well, after making this change, Rails bombed every time I tried to add another quote. For some reason, it didn't like the column to be of type text and have the same name as the Rails table object. I'm not exactly sure what or why specifically caused this problem, but it definitely didn't work. After some consultation with The Shawnami, the resident Rails guru, and some extensive frustration, we finally decided to try and just rename the column. Guess what? It worked perfectly after I renamed it content.
Leave a comment:
Popular Posts
Search
Tags
actionmailer activerecord ajax apache apple barcamp caching capistrano centos code golf css db delete eager loading ebay email attachment erb flash ftp fun generators get haml helpers ie sucks javascript jquery lightbox lost merb net ftp paperclip passenger php plexus post presentation rails rails machine railsconf redesign rest rjs routes rss ruby ruby on rails safari script sinatra symfony text replacement tips tutorial twitter xhtml
Projects
© 2010 Travis Roberts. All rights reserved.
The Shawnami said on June 15, 2006:
I think it might have to do with the fact that Rails quotes a string before putting it in the database and the method may have been 'quote' and it didn't like the column also being named 'quote'. Just a guess....