Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails: use jbuilder template in various controller methods

Is it possible to reuse jbuilder-template in another controller method? In other words: how to explicitly say controller method to use concrete jbuilder-template?

like image 896
meteor Avatar asked Jul 25 '15 20:07

meteor


1 Answers

From Rails guide.

Rendering an Action's Template from Another Controller.

What if you want to render a template from an entirely different controller from the one that contains the action code? You can also do that with render, which accepts the full path (relative to app/views) of the template to render. For example, if you're running code in an AdminProductsController that lives in app/controllers/admin, you can render the results of an action to a template in app/views/products this way

def my_action
  # some code here
  render "products/show"
end
like image 122
Philidor Avatar answered Sep 20 '22 13:09

Philidor