Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering inline in rails

I am trying to build a templating system which is in some ways similar to liquid but easier to use and less flexible/powerful.

Is there any way to render some inline content from the controller so that it also implements the layout erb file? So that I could render some custom content and it gets inserted into the main application theme?

The only way I can think of at the moment is to just add a one-liner in my view file that renders the inline content but this causes other problems.

If custom content is stored in the db then I want to render this inline (from the controller) within the layout but only if there is custom content otherwise I just want to render the normal view file.

Any ideas would be hugely appreciated!

like image 645
Nick Avatar asked Aug 14 '11 09:08

Nick


1 Answers

You can do that in the controller:

render :inline => "<%= 1+2 %>", :layout => "application"

Please note that if you don't put the :layout => "application", no template will be used.

More info at http://guides.rubyonrails.org/layouts_and_rendering.html

like image 184
Blacksad Avatar answered Oct 02 '22 07:10

Blacksad