Rails:未定义的方法text_field_tag
如果我使用 text_field
,我的 ERB 文件工作正常,但如果我切换到 text_field_tag
,我会收到此错误:
undefined method `text_field_tag' for #<ActionView::Helpers::FormBuilder:0x00000001f6fd50>
这是有效的代码:
<%= f.text_field mystring %>
以及无效的代码:
<%= f.text_field_tag mystring %>
text_field_tag已记录。如何让它发挥作用?我需要 require
或其他东西吗?
My ERB file works fine if I use text_field
, but if I switch to text_field_tag
I receive this error:
undefined method `text_field_tag' for #<ActionView::Helpers::FormBuilder:0x00000001f6fd50>
Here is the code that works:
<%= f.text_field mystring %>
And the code that does not work:
<%= f.text_field_tag mystring %>
text_field_tag is documented. How to make it work? Do I need a require
or something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
供您参考,
text_field_tag
来自ActionView::Helpers::FormTagHelper
,其中指出:由于这是一个不依赖于活动记录对象的帮助器,因此您无法为“f”对象调用此方法。这是一个辅助方法,应该像这样调用:
For your information,
text_field_tag
is fromActionView::Helpers::FormTagHelper
, which states :Since this is a helper that does not rely on an active record object, you cannot call this method for the "f" object. It's a a helper method that should be called like this :
需要删除f:
我猜text_field_tag不依赖于form_for。
Needed to remove f:
I guess text_field_tag does not rely on the form_for.