[英]Rails - how can I add a data attribute to a fields_for select tag
I'm using 我正在使用
<%= fields_for @reservation do |r| %>
....
<span data-to="date">
<%= r.select :end_day, options_for_select((0..7).map{|offset| Time.zone.today + offset}) %>
</span>
...
<% end >
to identify the element through the span but I would rather identify the select control itself and apply the data-to to it (not the individual options, though that will be next). 来确定跨度的元素,但我宁愿标识选择控件本身并将数据应用于该元素(不是单个选项,尽管接下来是)。
I tried 我试过了
<%= r.select :end_day, options_for_select((0..7).map{|offset| Time.zone.today + offset}), data:{to: 'date'} %>
but the attribute didn't show. 但该属性未显示。
<%= r.select :end_day, options_for_select((0..7).map{|offset| Time.zone.today + offset}), {}, data: {to: 'date'} %>
因为签名是:
select(method, choices, options = {}, html_options = {})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.