我正在尝试将刺激 Controller 连接到表单元素,该元素位于由简单表单 gem 生成的表单内。无论我做什么 - 相应的“data-controller”属性不会出现在最终呈现的页面中(因此, Controller 不会使用react)...
这是有问题的代码:
<%= simple_form_for book do |f| %>
<%= render 'shared/form_errors', form: f %>
...
<%= f.association :book_format, label: false, 'data-controller': 'book-format-select' %>
...
< % end %>
我也试过
<%= f.association :book_format, label: false, data_controller: 'book-format-select' %>
和
<%= f.association :book_format, label: false, html: {data-controller: 'book-format-select' } %>
这些都不起作用 - 输出总是相同的:
<select class="select required" name="book[book_format_id]" id="book_book_format_id">
不确定我做错了什么?
最佳答案
您需要使用 input_html
key
It is also possible to pass any html attribute straight to the input, by using the
:input_html
option
<%= f.association :book_format, label: false, input_html: { data: { controller: 'book-format-select' } } %>
关于ruby-on-rails - Rails simple_form 元素与数据-...刺激属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73402571/