instance method
search_field
Ruby on Rails 3.2.22.5
Since v3.0.20Signature
search_field(object_name, method, options = {})
Returns an input of type “search” for accessing a specified attribute (identified by method) on an object assigned to the template (identified by object_name). Inputs of type “search” may be styled differently by some browsers.
Examples
search_field(:user, :name) # => <input id="user_name" name="user[name]" size="30" type="search" /> search_field(:user, :name, :autosave => false) # => <input autosave="false" id="user_name" name="user[name]" size="30" type="search" /> search_field(:user, :name, :results => 3) # => <input id="user_name" name="user[name]" results="3" size="30" type="search" /> # Assume request.host returns "www.example.com" search_field(:user, :name, :autosave => true) # => <input autosave="com.example.www" id="user_name" name="user[name]" results="10" size="30" type="search" /> search_field(:user, :name, :onsearch => true) # => <input id="user_name" incremental="true" name="user[name]" onsearch="true" size="30" type="search" /> search_field(:user, :name, :autosave => false, :onsearch => true) # => <input autosave="false" id="user_name" incremental="true" name="user[name]" onsearch="true" size="30" type="search" /> search_field(:user, :name, :autosave => true, :onsearch => true) # => <input autosave="com.example.www" id="user_name" incremental="true" name="user[name]" onsearch="true" results="10" size="30" type="search" />
Parameters
-
object_namereq -
methodreq -
optionsopt = {}
Source
# File actionpack/lib/action_view/helpers/form_helper.rb, line 888
def search_field(object_name, method, options = {})
options = options.stringify_keys
if options["autosave"]
if options["autosave"] == true
options["autosave"] = request.host.split(".").reverse.join(".")
end
options["results"] ||= 10
end
if options["onsearch"]
options["incremental"] = true unless options.has_key?("incremental")
end
InstanceTag.new(object_name, method, self, options.delete("object")).to_input_field_tag("search", options)
end
Defined in actionpack/lib/action_view/helpers/form_helper.rb line 888
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::FormHelper