Multiple Rails forms on a page may clash ids

Posted . Visible to the public.

By default the Rails form_for helper adds ids to the form elements. If you have multiple forms for the same model on a single page, those ids will no longer be unique. This can cause problems with JavaScript which often gets elements by their id and may produce unexpected behavior if those ids are ambiguous.

Fortunately there is an easy fix: You can supply a :namespace option to the form_for helper. This will prefix the ids with the given value. Please note that ids cannot start with a number. Show archive.org snapshot

Philipp Antar
Posted by Philipp Antar to Distribusion IT (2013-10-25 08:36)