Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: storing erb templates in database

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

like image 224
Andrey Kuznetsov Avatar asked Apr 18 '10 01:04

Andrey Kuznetsov


2 Answers

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.

like image 193
retro Avatar answered Sep 19 '22 10:09

retro


I found better way:

def show
  @modal_popup = ModalPopup.find(params[:id])
  # erb = ERB.new(@modal_popup.content)
  # render :text => erb.result, :layout => false
  render :inline => @modal_popup.content, :layout => false
end

I use this action inside iframe or render the action from another views.

like image 37
Donny Kurnia Avatar answered Sep 20 '22 10:09

Donny Kurnia