Rails:将erb模板存储在数据库中 [英] Rails: storing erb templates in database

查看:59
本文介绍了Rails:将erb模板存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在数据库中存储erb模板?

Is it possible to store erb templates in database? How?

推荐答案

可以。

但是我认为,如果您只需要一些具有相同布局和不同内容的页面,这不是最佳解决方案。

But I think, this is not the best solution if you only need some pages with same layout and different content.

如果您确实希望将ERB保存在数据库中,请创建一些模型并保存您的ERB 。然后您可以像这样调用控制器代码以呈现该ERB。

If you really want ERBs saved in database, create some model with your ERBs saved in. Then you can call in controller code like this, to render that ERB.

erb = ERB_model.find(...)
@some_model_data = SomeModel.find(...)
erb = ERB.new(erb.source)
render :text => erb.result, :layout => true (or another)

观看 ERB.new 参数。

这篇关于Rails:将erb模板存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆