将 erb 从数据库渲染到视图中问题请帮忙!
我正在数据库中保存一些 erb 并在视图中渲染它,如下所示:
erb = ERB.new(content)
render :text => erb.result
尝试渲染 erb 时遇到错误,该 erb 中的 image_tag 保存在数据库中。错误是:
undefined method `image_tag' for main:Object
有人帮忙解决这个问题吗?我也收到 stylesheet_link_tag 的错误?
非常感谢 里克
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您需要将可选的绑定参数传递给 ERB::render 方法。这有效地提供了 ERB 模板范围内的局部变量。换句话说,绑定需要向模板提供 image_tag 变量。
我不知道您的情况下的“内容”是什么,但以下内容将从“父”视图传递绑定,假设 @obj.image_tag 从该视图可见:
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:
这是因为你的控制器中没有助手。您需要包括您使用的所有助手。
It's because you haven't helper in your controller. You need include all Helper do you use.