Quick question. I am an experienced developer but very new to Ruby on Rails. I am wondering how strictly one must follow the naming conventions. For instance, I am in the habit of using camel case for table names and lower case for all but the last letter of column names. It's just a habit that I have had for years and one with which I am very comfortable. I absolutely despise the practice of using an underscore to connect two words as is prescribed for instance variables in Ruby. What I am wondering is, will there be any problems if my models are in camel case and my instance variables are all lower case save for the last letter? I've seen some docs that say it could change the way the interpreter interacts with my models. I've seen other docs that say it's no big deal. How does all of this come into play in regards to scaffolding?
-
“I am in the habit of using…lower case for all but the last letter of column names”, really? So you have column names like “lastnamE”? – Andrew Marshall May 25 '13 at 18:43
-
Somewhat. More like if I had a table named Users I would have a columns named lastnameU, firstnameU, emailU etc. If the table were named HostCities I might have columns named countryHC, provinceHC, etc. It's just a habit I have developed over many years and the idea of having columns named country_hc would drive me crazy. – Blind Fish May 25 '13 at 18:47
-
That basically seems like hungarian notation for column names. The Rails convention would be to just name it `country` instead. Having an OO ORM makes your notation a bit silly (e.g. `HostCity.new.country_hc`). – Andrew Marshall May 25 '13 at 18:50
1 Answers
I believe some aspects of Rails will let you do what you wish (e.g., you can have an attribute start with an upper case letter rather than the generally assumed lower case), but it will be a lot more work for you if you deviate from their conventions. A lot of Rails framework functionality assumes the Rails convention and you might lose the ability to use some of those facilities. And then there are some I'm not sure there's a way to work around, like the naming of a file for a model (client_info.rb) versus the class inside (ClientInfo). Those are assumed to align.
My recommendation would be to learn the Rails way unless you want to live in your own Rails convention world, isolated from the rest of the Rails world. It bugged me too, at first, but I got used to it pretty quickly. :)

- 56,987
- 9
- 69
- 103
-
I too would recommend adapting. OP - Your comment about using camel case for table names... I have a feeling you're going to have a very very bad time in Rails if you do that. – Philip Hallstrom May 25 '13 at 17:45
-
Thanks for the quick responses. You're not saying what I wanted to hear, but I have a feeling that you're saying what I need to hear. Old dogs and new tricks, right? I thought I could get away with it as it created little or no problems for me using Php frameworks such as Yii. However, Ruby seems to be my Waterloo. Even worse is that I have an existing database I need to migrate to Ruby and it appears that this will involve renaming all of my tables and columns which is going to annoy the bejesus out of me. – Blind Fish May 25 '13 at 17:55
-
I feel your pain, BF. I think a lot of people go through that. Once you're in, though, I think you'll enjoy what Rails has to offer. Having to learn Rails forced me to learn more about the tools available in SQL and Rails to migrate information. So in the end, it's all good. – lurker May 25 '13 at 18:01
-
A bit of confusion now. I was just reading http://stackoverflow.com/questions/4893342/ruby-rails-models-named-with-two-words-naming-convention-issues?rq=1 and it says that model names SHOULD be camel case. Since models = tables shouldn't camel case table names be ok? See, this is what keeps throwing me. Every time I read one thing I find something else that says the opposite. – Blind Fish May 25 '13 at 18:05
-
And isn't this http://itsignals.cascadia.com.au/?p=7 essentially saying that models / tables should be camel case? Or am I reading this wrong? Either way it definitely appears that I will have to rename my columns. For me that will mean sticking with single world column names to avoid the hideous snake case underscore thing. I just can't bring myself to do that in code. It drives me crazy. – Blind Fish May 25 '13 at 18:10
-
When you reference the model (or I should say, ActiveRecord) in your Rails app, it's a camel case name. So if I am trying to find, say, a client data record, I might do something like `client = ClientData.find(123)` where 123 is the primary key (or `id` which is another Rails assumption on naming). But when Rails interacts with your database, it assumes the database uses the lower case and underscore method. Yes, it seems odd. So the internal Ruby/Rails representation is CamelCase, but the database itself is not. – lurker May 25 '13 at 18:10
-
I would recommend looking at the online Rails Guides such as http://guides.rubyonrails.org/ and check out RailsCasts eventually (www.railscasts.com) as a good source of info. – lurker May 25 '13 at 18:13
-
I just read what says at http://itsignals.cascadia.com.au/?p=7 and it's saying exactly what I'm saying: database tables are named lower case with underscores, and models are named camel case. – lurker May 25 '13 at 18:14