What is the difference between the render(:partial => 'article') and render_component?
on 2006-03-21 02:06
on 2006-03-21 08:40
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