views:

14

answers:

1

Hi,

I want to render action inside my erb template.

<div>
  <%= render :controller => :tags, :action => :tag_cloud %>
</div>

This block throws exception: undefined method `formats' for nil:NilClass

Also I want to tag_cloud action to be rendered from cache. Is that possible?

Regards, Alexey Zakhaov

+1  A: 

Just remind that render :action does not run the tags controller, it just renders the tag_cloud erb with the variables you have defined in your current controller. So you have to define in your controller all the instance variables you need in your template, including the one on which the formats method is called.

hellvinz
I was able to render action of another controller inside view when I was using ASP.NET MVC. I expect that same could be achieved with rails.
Alexey Zakharov
it used to exist, it was called render :component. But it was removed because considered as a code smell. The classic workaround is to set a before filter in application_controller that set the variables you need and a rendering a partial with the tag cloud in every view/layout you need them. You can cache the partial too to avoid rendering it every time.
hellvinz