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(:post, :title, :size => 20) # => <input name="post[title]" size="20" type="text" value="#{@post.title}" /> text_field(:post, :title, :class => "create_input") # => <input name="post[title]" type="text" value="#{@post.title}" /> text_field(:session, :user, :onchange => "if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }") # => <input name="session[user]" type="text" value="#{@session.user}" onchange="if $('session[user]').value == 'admin' { alert('Your login can not be admin!'); }" /> text_field(:snippet, :code, :size => 20, :class => 'code_input') # => <input name="snippet[code]" size="20" type="text" value="#{@snippet.code}" />
Source Code
# File action_view/helpers/form_helper.rb, line 307 def text_field(object_name, method, options = {}) InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_input_field_tag("text", options) end
<code/>and<pre/>for code samples.