Most of the Rails application I build these days have no use whatsoever for the autocomplete feature modern browsers.

FireFox and Internet Explorer have extended the input element to provide an autocomplete attribute.

This attribute may be set to on or off, indicating whether autocomplete should be enabled, on a field-per-field basis.

In Rails, that translates to:

1 <%= text_field :payment, :credit_card,
2         :autocomplete => 'off' %>

Obviously, if we have ten fields on the form, that would not be very DRY

Instead, you can do the following:

app/helpers/application_helper.rb
 1 module ApplicationHelper
 2   def text_field(*args)
 3     unless args.last.kind_of?(Hash) then
 4       args << {}
 5     end
 6 
 7     args.last[:autocomplete] = 'off' \
 8         unless args.last[:autocomplete]
 9     super(*args)
10   end
11 end

This is great when most of your fields need to have autocomplete disabled. But, while researching this topic, I stumbled on How to Turn Off Form Autocompletion
for Mozilla based browsers.

You do it this way:

1 <%= start_form_tag({}, {:autocomplete => 'off'}) %>
2   ...
3 <%= end_form_tag %>

The same trick as above for overriding text_field_tag can be used to override form_tag.

Search

Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend

Links

Projects I work on

Projects I worked on