Multiple Controllers in a page?

Hi all,

I recently posted this on the ruby group instead of here :frowning:

but here is what I am attempting to do.

I am building a site, and I wish to populate the navigation dynamically
from a MySQL db table, and the page content from a different table.

The idea being I can have the navigation on every page, and use
different controllers to select different content depending on what is
needed.

example:
The Event page content comes from a page table where id = someValue
but I also need some events (days out etc, presentations), they come
from the events table.

I am confused how to put all the pieces together in one page.

Could anyone point me in the right direction?

**
At the moment I have a Site Controller, NavItem controller/model (with
a partial _nav_item), Event controller/model and Page controller/model,
all of which have the functions for list/show etc inside their
respective controller, except the Site.

Since I posted I have created a partial for my nav_items, but how do I
then render my partial in another controller? I can’t understand how I
could just use
<%= render :partial => “nav_item”, object => @nav_item %>
and rails know what “nav_item” is.

Should I be looking at using a template?

If someone could provide some clarification on what I am doing wrong,
or if I am trying to structure it wrong, that would be great :slight_smile:

Cheers,
Kev

  1. About the Navigation:

add a before_filter to your app controller that calls a method to
build the data for your sidebar

before_filter :build_sidebar

private
def build_sidebar
if controller_name = “page”
do something
elseif controller_name = “someothercontroller”
do somethingelse
end
end

and then render your navigation partial in your layout
(application.rhtml):
<%= reder :partial => :navigation %>
and in your _navigation.rhtml you build your naviation based on the
variables/data populated in the beforefilter.

2’) about the “different controllers in one page”
i think you are thinking the wrong way. you have a controller for each
Model, and want to put those controllers together. You dont need 1
controller for each model.
Instead, you should have a controller for each section/logic of your
site, and in each of these controllers you access various Models to
create your views etc.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs