Noob Question about databases in rails


#1

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 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) 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.


#2

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) 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


#3

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