# Noob Question about databases in rails

**URL:** <https://www.ruby-forum.com/t/noob-question-about-databases-in-rails/52193>\
**Category:** Rails\
**Created:** [December 5, 2005, 9:18am UTC](https://www.ruby-forum.com/t/noob-question-about-databases-in-rails/52193 "2005-12-05T09:18:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [December 5, 2005, 9:18am UTC](https://www.ruby-forum.com/t/noob-question-about-databases-in-rails/52193/1 "2005-12-05T09:18:29Z")

</div>

Ok,

This sounds like it should be easy but I am having a hard time with it.  
I am making a website but I’m trying to make everything in it fairly  
database driven, this is really pretty much my first rails project.

I have a table called ‘nav\_items’ to display the nav choices, but there  
is also other dynamic data on the homepage such as the ‘events’ which  
I’ve created a table for. So I want them to be both pulled into the  
homepage which is at [http://localhost:3000/home](http://localhost:3000/home) on my system right now.  
So to get the data I create models ‘events’ and ‘nav\_items’, don’t I  
need a controller for each to pull out the data? And when I call that  
controller ([http://localhost:3000/nav\_items](http://localhost:3000/nav_items)) then it will take me away  
from home?

Basically I’m looking to put all this data on one page without having to  
call 2 different controllers?

I hope this all makes sense.

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [December 5, 2005, 9:34am UTC](https://www.ruby-forum.com/t/noob-question-about-databases-in-rails/52193/2 "2005-12-05T09:34:50Z")

</div>

> So to get the data I create models ‘events’ and ‘nav\_items’, don’t I  
> need a controller for each to pull out the data? And when I call that  
> controller ([http://localhost:3000/nav\_items](http://localhost:3000/nav_items)) then it will take me away  
> from home?

You dont need 2 controllers,you can access all the models from one  
controller. btw the model name is singular (thats the rails default)  
and  
the table name is plural.So i presume the database name is events and  
the  
model name is Event.  
So you can access them like this

Nav\_item.find(id)  
Event.find(id)

both can be accessed from one controller.  
Vivek

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [December 5, 2005, 3:09pm UTC](https://www.ruby-forum.com/t/noob-question-about-databases-in-rails/52193/3 "2005-12-05T15:09:47Z")

</div>

in Controller of whatever name

@x = model\_1.find(:all)  
@y = modell\_2.find(:all)

Now you can manipulate and present the data as needed. In other  
words, one controller can make multiple calls to a model and store  
the data in an array.

Does that answer your question?

bruce
