从分部视图调用辅助方法
在我的 bar.html 中,我渲染了一个部分视图,在其中我想调用方法 foo(var1, var2) 并获取一个数组。在我的本地系统上,一切正常,但在我的生产系统上,出现以下错误。
undefined local variable or method `foo' for #<#<Class:0x70c6410>:0x706f480>)
有人可以向我解释一下吗?
类#<#:0x706f480>每次调用都会发生变化,因此视图似乎不会尝试在我的助手中搜索该函数。
编辑:
应用程序具有以下结构(示例)
app/helpers/bar_helper
app/views/bar/bar.html.erb
app/views/bar/partials/bar_partial.html.erb
,在 bar_partial.html.erb 中,我在 bar_helper 中调用 foo(var1, var2) ,如下所示
<% data = foo(var1, var2) %>
In my bar.html I render a partial view and in it I want to call the method foo(var1, var2) and get an array back. On my local system everything works finde but on my production system the following error occurs.
undefined local variable or method `foo' for #<#<Class:0x70c6410>:0x706f480>)
Can someone explain this to me?
The Class #<#:0x706f480> changes with every call so it seems that the view does not try to search the function in my helper.
EDIT:
The application has the following structure (example)
app/helpers/bar_helper
app/views/bar/bar.html.erb
app/views/bar/partials/bar_partial.html.erb
and in bar_partial.html.erb I call foo(var1, var2) in my bar_helper like this
<% data = foo(var1, var2) %>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是,该类在文件夹结构中的某个位置第二次存在,因此 ruby 找到了第一个文件并使用该文件而不是正确的文件。
The problem was, that the class existed a second time somewhere in the folder structure so that ruby found the first file and used that one instead of the right one.