My suggestion would be to populate @categories with a before_filter
defined in the parent class. Then your layouts can just reference
them as per normal. This sticks with the MVC pattern.
Controllers prepare models for the views to render.
In practise you may want to use a helper to find_all, but it seems
''messy'' to me.
On Wed, 5 Jan 2005 22:24:35 +0100, Lars Hoss
<woeye-DgJLf6aGC0jR7s880joybQ@public.gmane.org>
wrote:> Hi all!
>
> I want to show a list of all available categories on various pages.
> Thus I put the HTML-code into a layout. In order to get the list of
> categories I have to talk to the database using AR. The question now
> is: where to put that code? My first idea was to put the code into
> ApplicationHelper:
>
> module ApplicationHelper
> def categories
> return Category.find_all
> end
> end
>
> Since I need the model Category I though "well, there''s this
new cool
> dependency feature" and wrote:
>
> module ApplicationHelper
> module :category
> def categories
> return Category.find_all
> end
> end
>
> This, however, only works for controllers and not helpers. Therefore
> the correct way is:
>
> require ''Category''
> module ApplicationHelper
> def categories
> return Category.find_all
> end
> end
>
> Personally I find this a little bit confusing because controllers use
> the "model :" approach whereas helpers must use the old-style
"require"
> approach. If you know what to do it''s ok. Newbies on the other
hand
> might be confused a little bit first (when to use what)?
>
> Yours,
> Lars
>
> --
> "Stil ist die Fähigkeit, komplizierte Dinge einfach zu sagen - nicht
> umgekehrt." -- Cocteau, Jean
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Cheers
Koz