When using the form_for
helper and a text_field
call, Ruby on Rails will generate a unique id for the element that it outp
I don't really like my own solution that much, but I tried not to go and patch InstanceTag.
Unfortunately that meant lifting the sanitization code from ActionView::Helpers::InstanceTagMethods
class MyCoolFormBuilder < ActionView::Helpers::FormBuilder
def sanitized_object_name
@sanitized_object_name ||= object_name.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
end
def field_id_for(method)
"#{sanitized_object_name}_#{method.to_s.sub(/\?$/,"")}"
end
end