簡體   English   中英

Rails-如何將數據屬性添加到fields_for select標簽

[英]Rails - how can I add a data attribute to a fields_for select tag

我正在使用

<%= 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 >

來確定跨度的元素,但我寧願標識選擇控件本身並將數據應用於該元素(不是單個選項,盡管接下來是)。

我試過了

 <%= r.select :end_day, options_for_select((0..7).map{|offset| Time.zone.today + offset}), data:{to: 'date'} %>

但該屬性未顯示。

 <%= 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM