局部变量未通过渲染传递给部分模板?
我似乎无法将变量传递给 Rails (2.3.5) 中的部分模板。我的代码如下;
在主视图 .html.erb 文件中:
<% f.fields_for :payments do |payment_form| %>
<%= render 'payment', {:f => payment_form, :t => "test" } %>
<% end %>
和在 _ payment.html.erb 文件中:
<%= t %>
产生参数数量错误(0 代表 1)
错误。 payment_form 对象作为 f 传递给部分,没有任何问题。我尝试了上述语法的多种变体(例如 :locals => {:f => payment_form, :t => "test" }
但没有成功。我想我'我做了一些非常基本的错误,但只是看不到它。
I don't seem to be able to pass a variable to my partial template in rails (2.3.5). My code is as follows;
In the main view .html.erb file:
<% f.fields_for :payments do |payment_form| %>
<%= render 'payment', {:f => payment_form, :t => "test" } %>
<% end %>
and in the _payment.html.erb file:
<%= t %>
produces a wrong number of arguments (0 for 1)
error. The payment_form object is being passed to the partial as f without any problems. I've tried a number of variations on the above syntax (e.g. :locals => {:f => payment_form, :t => "test" }
without success. I presume I'm doing something pretty basic wrong but just can't see it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能是因为 t() 是用于 I18n 的保留视图帮助器方法。只需将其重命名为更具描述性的名称即可
It's probably because t() is a reserved view helper method used for I18n. Just rename it to something more descriptive
尝试
Try
你尝试过吗
<%= 渲染“付款”, :f => payment_form %>
我不确定 :t 的用途是什么,但 Rails 显然是说你应该只传递一个额外的参数,并且参数数量错误(0 代表 1)错误。
Have you tried
<%= render 'payment', :f => payment_form %>
I'm not sure what the :t is for, but rails is obviously saying that you should only be passing in one extra parameter with the wrong number of arguments (0 for 1) error.