Hacker News new | ask | show | jobs
by qaexl 6782 days ago
I just found this out five minutes ago -- You can get a plugin called "embedded actions" for Rails (2.0, and probably 1.2.x). The README is here: http://dev.notso.net/svn/rails/plugins/embedded_actions/trun...

A snippet from the README:

Unlike partials, embedded actions also let you define business logic to be performed before the partial is included. That logic is encapsulated in the already well understood metaphor of an action inside a controller.

So a simple call like

<%= embed_action :controller => "songs", :action => "top10" %>

lets you include an html fragment containing the top 10 songs into any of your pages, regardless of which controller, action or view wants to do the including.

----

In other words, you call "embed_action" from within a view which will call the controller-action and embed whatever result is there. You still get the organizational benefit of MVC without the hassle of rolling your own partials.

As an additional note to what I was saying about partials, Rails 2.0 also has a concept of "partial layouts", allowing you to switch out the surrounding content of a partial.