# Database and MVC

**URL:** <https://www.ruby-forum.com/t/database-and-mvc/92757>\
**Category:** Rails\
**Created:** [April 23, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/database-and-mvc/92757 "2007-04-23T22:27:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![smital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@smital](https://www.ruby-forum.com/u/smital)\
**Post date:** [April 23, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/database-and-mvc/92757/1 "2007-04-23T22:27:55Z")

</div>

I have just discovered Ruby on Rails and I have been going through the  
tutorial “Rolling with Ruby on Rails revisited”.

> **[Radar - O’Reilly](https://www.oreilly.com/radar/)**
>
> Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology

One thing that baffles me is that we create my sql tables “recipes”  
and “categories”. We then generate ruby scaffold using the command

ruby script/generate scaffold recipe recipe  
ruby script/generate scaffold category category

As you can see that the model and controller arguments are spelt  
differently from the database table names. How does the framework  
associate the right table to the right model and controller classes.

Moving further on in the tutorial I notice that the model classes  
Category and Recipe have the following line of code added to them-  
class Category \< ActiveRecord::Base  
has\_many : recipes  
end

class Recipe \< ActiveRecord::Base  
belongs\_to : category  
end

It looks like that the framework uses “recipes” and “recipe” &&  
“category” and “categories” interchangeably.

Can someone throw some light on this issue?

Thank you,  
S

---

<div class="post-metadata">

**Author:** ![smital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@smital](https://www.ruby-forum.com/u/smital)\
**Post date:** [April 23, 2007, 10:31pm UTC](https://www.ruby-forum.com/t/database-and-mvc/92757/2 "2007-04-23T22:31:32Z")

</div>

This is the “famous” convention over configuration. Rails uses a  
heuristic that says “pluralize my model name to find the table name”  
(and similarly, singularize the table name to find my model name".

Its knowledge of appropriate plural identifiers is quite broad, hence  
the category cleverness.

See the Infector module in the API docs. for more information.

Wes

---

<div class="post-metadata">

**Author:** ![smital](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4bbf92/32.png) [@smital](https://www.ruby-forum.com/u/smital)\
**Post date:** [April 23, 2007, 10:31pm UTC](https://www.ruby-forum.com/t/database-and-mvc/92757/3 "2007-04-23T22:31:48Z")

</div>

er, Inflector :).
