Links
Embedded Actions
Categories
Embedded Actions
Just like the traditional render :partial, embedded actions allow you to
refactor your views and extract presentation logic and templates into separate
files.
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.
Additionally, embedded actions can provide caching of their results (allowing
for different parameters) just like page caching, but at the level of html
fragments. So your dynamic pages can still be rendered dynamically, but some of
the embedded actions can be cached (and expired) independently.
Just declare an action as 'cacheable' in a way similar to page caching,
by invoking "caches_embedded" with the name of the action to cache.
class TestController < ApplicationController
caches_embedded :user_list
def user_list
...
end
end
Cached fragments can be invalidated with calls to expires_embedded, but you must
remember to use the same set of parameters used to embed the cached action in
the first place.
Vitals
| Home | http://www.notsostupid.com/blog/2007/10/23/the-embedded-actions-plugin-for-rails/ |
|---|---|
| Repository | http://dev.notso.net/svn/rails/plugins/embedded_actions/current/ |
| License | BSD |
| Tags |
component
|
| Rating | (12 votes) |
| Owner | Sebastian Delmont |
| Created | 24 October 2007 |
Comments
-
it's a pretty cool plugin.
-
This is just great .. i´m using it for dynamic menus and "widget" like snippets
-
Nice plugin, but there is a problem with Rails 2.0: If you have the application protected with "protect_from_forgery" and do a "post" request with embedded actions included, the exception "ActionController::InvalidAuthenticityToken" is raised.

