Forum: Ruby on Rails render :partial => :url - is it possible?

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.
F46f6af020ef76c9e1793adb9e0120ad?d=identicon&s=25 James McGuigan (Guest)
on 2007-06-21 21:30
(Received via mailing list)
Hi, this is my first post to the list. I'm still learning the rails
framework, having done most of my previous web development in PHP. I've
done a bit of googling for the answer to this question, but maybe I'm
just lacking the right word to search for.

Several parts of my site, such as sidebar components, are
self-contained, modularized and re-used in several parts of the site.
The sidebar is part of the layout (I'm using the nested_layout plugin),
rather than the page view.

# /app/layouts/layout_3_col.rhtml
<div class='col_left col'><div class='inner'>
<%= render :partial => @col_left_partial || 'col_left' %>
</div></div>


However this means I need to generate the data for the sidebar
components within each model, and not more-cleanly in a separate model
for the sidebar component itself.

What I am after is a system where I could create a separate model, view
and controller for each sidebar component and then call render :url =>
/sidebars/left_col/3

I'm assuming a similar approach would be used in AJAX, where you replace
a DIV with a HTML fragment generated on the server, but would want to
show the fragment as part of the original page without generating a
series of AJAX requests on page load.

Is this possible in rails, whats the technique called (so I can google
for it) or am I going about it the wrong way.

Thanks in advance.

--
James
2f9a03aa0fcfe945229cb6126eda2cb2?d=identicon&s=25 Philip Hallstrom (Guest)
on 2007-06-21 22:01
(Received via mailing list)
> # /app/layouts/layout_3_col.rhtml
> and controller for each sidebar component and then call render :url =>
> /sidebars/left_col/3

What you are looking for is in fact called "components" which are going
out of style (if they aren't already) as they are inefficient.

If you have a sidebar that is shared among many areas of the site, yet
is
totally self contained, I would simply break MVC a little bit and make a
"MySideBarModel.find...." call followed by the rendering code to display
it.

Yes, it breaks MVC, but it's a much simpler in a lot of ways.

Or if it's really shared *everywhere* create a before_filter in your
application.rb that loads up the data needed for every request.

-philip
This topic is locked and can not be replied to.