How to get the automatically generated ID for an actionview form helper 'number_field' input?

StackOverflow https://stackoverflow.com/questions/13801192

Вопрос

I'm trying to retrieve an ID that is being generated for an input via the number_field actionview form helper.

I am updating some existing code which has the following input without a label:

<%= item_form.number_field :quantity, :min => 0 %>

When I try adding a label like this:

<%= label_tag :quantity, "Foo" %>

the 'for' attribute of the label tag comes out as 'quantity' whereas the id of the number field comes out as 'order_line_items_attributes_0_quantity'

As there may be several of these fields on the page, I cannot have a static ID.

TIA.

Это было полезно?

Решение

<%= item_form.label :quantity, "Foo" %> should generate "for" attribute with the right ID.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top