Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top