instance method
password_field
Ruby on Rails 7.1.6
Since v2.2.3Signature
password_field(object_name, method, options = {})
Returns an input tag of the “password” 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. For security reasons this field is blank by default; pass in a value via options if this is not desired.
Examples
password_field(:login, :pass, size: 20) # => <input type="password" id="login_pass" name="login[pass]" size="20" /> password_field(:account, :secret, class: "form_input", value: @account.secret) # => <input type="password" id="account_secret" name="account[secret]" value="#{@account.secret}" class="form_input" /> password_field(:user, :password, onchange: "if ($('#user_password').val().length > 30) { alert('Your password needs to be shorter!'); }") # => <input type="password" id="user_password" name="user[password]" onchange="if ($('#user_password').val().length > 30) { alert('Your password needs to be shorter!'); }"/> password_field(:account, :pin, size: 20, class: 'form_input') # => <input type="password" id="account_pin" name="account[pin]" size="20" class="form_input" />
Parameters
-
object_namereq -
methodreq -
optionsopt = {}
Source
# File actionview/lib/action_view/helpers/form_helper.rb, line 1194
def password_field(object_name, method, options = {})
Tags::PasswordField.new(object_name, method, self, options).render
end
Defined in actionview/lib/action_view/helpers/form_helper.rb line 1194
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionView::Helpers::FormHelper