문제

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