instance method
text_field
Ruby on Rails 8.1.2
Since v2.2.3Signature
text_field(object_name, method, options = {})
Returns an input tag of the “text” type tailored for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object). Additional options on the input tag can be passed as a hash with options. These options will be tagged onto the HTML as an HTML element attribute as in the example shown.
Examples
text_field(:article, :title, size: 20) # => <input type="text" id="article_title" name="article[title]" size="20" value="#{@article.title}" /> text_field(:article, :title, class: "create_input") # => <input type="text" id="article_title" name="article[title]" value="#{@article.title}" class="create_input" /> text_field(:article, :title, maxlength: 30, class: "title_input") # => <input type="text" id="article_title" name="article[title]" maxlength="30" size="30" value="#{@article.title}" class="title_input" /> text_field(:session, :user, onchange: "if ($('#session_user').val() === 'admin') { alert('Your login cannot be admin!'); }") # => <input type="text" id="session_user" name="session[user]" value="#{@session.user}" onchange="if ($('#session_user').val() === 'admin') { alert('Your login cannot be admin!'); }"/> text_field(:snippet, :code, size: 20, class: 'code_input') # => <input type="text" id="snippet_code" name="snippet[code]" size="20" value="#{@snippet.code}" class="code_input" />
Parameters
-
object_namereq -
methodreq -
optionsopt = {}
Source
# File actionview/lib/action_view/helpers/form_helper.rb, line 1175
def text_field(object_name, method, options = {})
Tags::TextField.new(object_name, method, self, options).render
end
Defined in actionview/lib/action_view/helpers/form_helper.rb line 1175
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::FormHelper