Thanks. But I’m just beginning with Rails and I’m now making an ultra-
simple application so I would like to do it myself. I feel that way I
will understand rails better. So I’m looking for a way I can implement
that functionality in a simple, standard-rails way.
Thanks. If I use a partial in my main layout and use an if in the
partial. Like:
if (:controller == ‘dashboard’)
(or something like that)
would that be considered a hack? Is there a nicer way?
No, but there may be a better way of doing it, depending on what you’re
going to be showing. If the furniture (for want of a better word) is
substantially different on the dashboard controller, you may be better
off with separate layout for that controller. Or if the partials are
dependent on dynamic data, then set that data up in the method called by
the filter (in my application controller I have before_filter
:setup_layout_furniture), and do the testing againt the controller in
the method called. The idea is to keep the views (and layouts) as clean,
readable, and DRY as poss.
In my case @menus is a collection of Menu instances, but you could
easily have it as an array of links, strings, or whatever. Hope this
makes sense,
Chris
What’s the best way to do this? I heared something about partials/
components?
The easy way is to use instance variables to hold the data, perhaps set
up using filters in the application controller – @menus, @sidebars,
etc, and then rendering using a partial if they have been set: render
:partial => ‘sidebar’ if @sidebar, for example. It can get more
sophisticated than this, with a custom class for each type of furniture
(one for menus, one for sidebars, etc), but hopefully this helps a
little to start with.
Chris
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.