Built-in Rail Rendering

I am trying to create a template system that is somewhat similar to liquid, but easy to use and less flexible / powerful.

Is there a way to render some inline content from the controller so that it also implements the erb file of the layout file ? So that I can visualize some kind of user-generated content and is it inserted into the main theme of the application?

The only way I can think of now is to simply add a single line file to the view file, which displays inline content, but this causes other problems.

If user content is stored in db, I want to display this inline (from the controller) in the layout, but only if there is user content, otherwise I just want to display a regular view file.

Any ideas would be greatly appreciated!

+6
source share
1 answer

You can do this in the controller:

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

Note that if you do not put :layout => "application" , the template will not be used.

Additional information at http://guides.rubyonrails.org/layouts_and_rendering.html

+8
source

Source: https://habr.com/ru/post/895004/


All Articles