Hi all,
I recently posted this on the ruby group instead of here :(
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 :)
Cheers,
Kev
Gustav Paul wrote:> Kev wrote:
> > Hi all,
> >
> Hey
> > 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
> It sounds like this is the kind of thing you''d want in your
layout, or,
> if you''re using more than one layout, the navigation should be in
a
> partial that you could then render in each of the particular layouts...
> > , and use
> > different controllers to select different content depending on what is
> > needed.
> >
> I''m not quite sure what you mean, but ''content''
usually refers to the
> views that get rendered by the actions in your controllers...So
> ''depending on what''s needed'' usually means you
have seperate views for
> your different actions.
> > example:
> > The Event page content comes from a page table where id = someValue
> > but I also need some events, they come from the events table.
> >
> This sounds like you''ve a view that should look as follows...?
>
> <div id="page_content">
> <%= Page.find_by_controller_and_action("event",
"list").page_content %>
> </div>
> <div id="event_list">
> <%= Event.find(:all, :order => ''created_at desc'',
:limit => 20).each
> do |event| %>
> <!-- do something with ''event'', eg. -->
> <div id="event_<%=event.id%>">Title:
<%=event.title%> </div>
> <% end %>
> </div>
>
> Assuming you''re keeping the page content in a table called pages
with
> atleast four columns: id, controller and action (which together specify
> which action in which controller should have the text rendered in the
> view for) and page_content, which contains the actual page content.
I''m
> assuming since you want to display a list of events, you''re
rendering
> the ''list'' action in an event_controller (I''m
guessing here :] ). The
> previous post suggested getting this kind of data in your controller and
> pass it to this view as instance variables, this is better practice.
>
> The second part of the code will get the last 20 events and display
> their titles.
> > I am confused how to put all the pieces together in one page.
> >
> I hope the above code helps. I''m almost 100% sure I don''t
understand
> what you want fully, if you''d care to elaborate a little bit more
I''d be
> happy to help you as best I can.
> > Could anyone point me in the right direction?
> >
> >
> The right direction is undoubtedly on the Rails Mailing List :]
> rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>
> The previous post suggested components,
> Some people believe they are evil ... It''s your call though :] If
you''re
> using components, you most likely want to be using partials instead, but
> that''s a 100% IMHO!
>
http://glu.ttono.us/articles/2006/08/30/guide-things-you-shouldnt-be-doing-in-rails
> The basic idea is that using a component is like calling a new action,
> with rendered view etc, so unless you want to include an entire other
> view that already lives elsewhere in your app, use a partial
> instead...if of course that is the case, then using a component is perfect.
>
> Anyway, Cheery-O
> Gustav Paul
> gustav-PUm+PnBUKx7YkQIYctQFYw@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---