开发者

render erb from database into view problem please help!

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 er开发者_开发百科ror 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


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) %>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜