views:

33

answers:

2

hi all

i am saving some erb in my database and rendering it in the view like this:

erb = ERB.new(content)
render :text => erb.result

I am getting errors when trying render erb that has the image_tag in the erb saved in the database. The error is :

undefined method `image_tag' for main:Object

Anyone help on this ? i also get the error with the stylesheet_link_tag ?

Thank alot rick

A: 

It's because you haven't helper in your controller. You need include all Helper do you use.

shingara
i am not doing this from the controller. I am doing this in side a view. any ideas?
rick moss
A: 

I think that you would need to pass the optional binding parameter to the ERB::render method. This effectively provides the local variables in the scope of the ERB template. In other words the binding needs to provide the image_tag variable to the template.

I don't know what 'content' is in your case but the following will pass the binding from the 'parent' view assuming that @obj.image_tag is visible from that view:

<%= ERB.new("image tag - \<\%= @obj.image_tag \%\>").result(binding) %>
Steve
thanks very much
rick moss