Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between tableize and underscore in rails

Not sure what the difference between underscore (student_state) and tableize (student_states), other than tableize also pluralizes. However, not sure how they can be used differently. Obviously, you can use tableize to reference table name in database. But what different functionality does underscore provide, such as when you see :student_state compared to :student_states when used as symbols. Thanks for suggestions.

like image 835
JohnMerlino Avatar asked Jan 30 '10 02:01

JohnMerlino


1 Answers

tableize will pluralize your string whether the original was singular or plural, while underscore will only add underlines.

While this may seem trivial, it's all about abstracting the details of database implementation away from the developer. If, down the road, Rails began formatting table names differently, the only method that would need to change would be tableize. All other places in the Rails code that refer to table names can stay the same, because they're still calling the tableize method. A change to the underlying structure of rails is therefore limited and much less damaging.

This is referred to as "orthoganality" in computer science. Now that you know what it means, try to throw it around in conversation to make yourself look smarter. Did it work for me? :)

like image 179
Jaime Bellmyer Avatar answered Oct 22 '22 16:10

Jaime Bellmyer