Forum: Ruby on Rails Noob Question about databases in rails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E25296bf52723dc37bc462271eb02d2d?d=identicon&s=25 jpfeifer (Guest)
on 2005-12-05 09:18
(Received via mailing list)
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.
6828ffc79486cd2442714bf32286a910?d=identicon&s=25 krishna.vivek (Guest)
on 2005-12-05 09:34
(Received via mailing list)
>
> 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
2dd904ec5981c31e7bb7a5743a53caf8?d=identicon&s=25 Bruce Balmer (brucebalmer)
on 2005-12-05 15:09
(Received via mailing list)
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
This topic is locked and can not be replied to.