渲染erb从数据库到查看问题请帮助! [英] render erb from database into view problem please help!

查看:118
本文介绍了渲染erb从数据库到查看问题请帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的数据库中保存一些erb,并在视图中呈现如下:

  erb = ERB.new内容)
render:text => erb.result

我在尝试渲染erb时遇到错误,并且将ert中的image_tag保存在数据库。错误是:

 未定义方法`image_tag'for main:Object 
pre>

有人帮忙吗?我也得到了stylesheet_link_tag的错误?



谢谢alot
rick

解决方案

我认为你需要将可选的绑定参数传递给ERB :: render方法。这有效地提供了ERB模板范围内的局部变量。换句话说,绑定需要为模板提供image_tag变量。



我不知道你的情况是什么'内容',但下面的内容将通过绑定从父视图中假设@ obj.image_tag在该视图中可见:

 <%= ERB.new image tag  -  \< \%= @ obj.image_tag \%\>)。result(binding)%> 


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

解决方案

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

这篇关于渲染erb从数据库到查看问题请帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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