Turn autocomplete off with rails form_tag
autocomplete, autofill, forms, ruby-on-rails
Solution
As of Rails 4+
Disable autocomplete for an entire form with `form_tag`:
= form_tag admin_sessions_path, html: { autocomplete: "off" } do
Disable autocomplete for an entire form with `form_for`:
= form_for @user, html: { autocomplete: "off" } do |f|
Disable autocomplete for a single form element:
= f.text_field :foo, autocomplete: 'off'
Hope this helps!
Problem
I'm trying to turn autocomplete off in one of my rails forms. Here's what I've tried so far: ``` # add it at the form level = form_tag admin_sessions_path, autocomplete: "off" do ``` That didn't work. ``` # add it at the element level .panel = label_tag :email = email_field_tag :email, params[:email], autocomplete: 'off' ``` Neither did that. ``` # add it to both = form_tag admin_sessions_path, autocomplete: "off" do # add it at the element level .panel = label_tag :email = email_field_tag :email, params[:email], autocomplete: 'off' ``` When I visit my form, my email address and saved password are already filled-in. What am I doing wrong here? I love rails, but it really drives me mad sometimes.