Rails:未定义的方法text_field_tag [英] Rails: undefined method text_field_tag

查看:111
本文介绍了Rails:未定义的方法text_field_tag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 text_field ,我的ERB文件工作正常,但是如果切换到 text_field_tag ,我会收到此错误:

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>

这是有效的代码:

<%= f.text_field mystring %>

无效的代码:

<%= f.text_field_tag mystring %>

text_field_tag 。如何使其运作?我需要需求或其他东西吗?

text_field_tag is documented. How to make it work? Do I need a require or something?

推荐答案

text_field_tag 来自 ActionView :: Helpers :: FormTagHelper ,其中指出:



提供了多种创建表单标签的方法,这些标签不依赖
分配给
的Active Record对象,该模板就像FormHelper一样。
而是您手动提供名称和
值。

Provides a number of methods for creating form tags that doesn’t rely on an Active Record object assigned to the template like FormHelper does. Instead, you provide the names and values manually.

因为这是一个不依赖的助手在活动记录对象上,不能为 f对象调用此方法。这是一个应该这样的帮助方法:

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 :

<%= text_field_tag "whatever you want to write" %>

这篇关于Rails:未定义的方法text_field_tag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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