Forum: Ruby on Rails What is the difference between render partial and component?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Abb249055208c7af4d35568e422dfd63?d=identicon&s=25 Guest (Guest)
on 2006-03-21 02:06
What is the difference between the render(:partial => 'article') and
7223c62b7310e164eb79c740188abbda?d=identicon&s=25 Xavier Noria (Guest)
on 2006-03-21 08:40
(Received via mailing list)
On Mar 21, 2006, at 2:06, Guest wrote:

> What is the difference between the render(:partial => 'article') and
> render_component?

A partial is just a template, render :partial specifies you want to
render a chunk of view, either from another template, or as view of
some action that has no layout. A partial template has no
corresponding action.

On the other hand render_component means "invoke this action in this
controller with this parameters and include its output here".

As a rule of thumb, if there's a reusable piece of template that oly
renders stuff already known to the templates it belongs you factor
that out as a partial. A partial may be suitable also for actions
that only respond to Ajax calls, though there you only use the fact
that there's no layout. In that case my personal choice is a regular
template with :layout => false.

Otherwise, if that piece of view needs some application logic, like a
shopping cart summary in the main layout of a shop, it is cleaner to
call the shopping cart controller from the layout and delegate the
logic to build that part to the controller that knows about it.

If some piece of view is not reusable but is rendered both as part of
a normal template and as an Ajax call that updates that piece later,
I factor that out as render_component when building the first non-
Ajax response as well.

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