Rails: storing erb templates in database

后端 未结 3 1001
死守一世寂寞
死守一世寂寞 2020-12-17 02:20

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

3条回答
  •  囚心锁ツ
    2020-12-17 02:49

    Sure it is.

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

    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)
    

    Watch ERB.new parameters.

提交回复
热议问题