简单形式:html属性

时间:2014-08-12 09:23:57

标签: ruby-on-rails ruby-on-rails-4 simple-form

如何将自定义html属性data-uk-toggle粘贴到simple_form标签中,如

<span class="uk-button" data-uk-toggle="{target:'.my-class'}">...</span>

我试过

<%= g.label :self_estimation, class: 'km-180-label', input_html: { "data-uk-toggle" => "{target:'.my-class'}" } %>

但它不起作用

3 个答案:

答案 0 :(得分:0)

你需要做的是这样的事情:

<%= g.input :self_estimation, label_html: { class: 'km-180-label', :data-uk-toggle => "{target:'.my-class'}" } %>

您可以在Simple Form

找到更多详细信息

答案 1 :(得分:0)

尝试:

<%= g.input :self_estimation, label_html: { class: 'km-180-label', "data-uk-toggle" => "{target:'.my-class'}" } %>

OR

<%= g.input :self_estimation, label_html: { class: 'km-180-label', data: {uk_toggle: "{target:'.my-class'}"} } %>

OR

<%= g.label :self_estimation, :class => 'km-180-label', "data-uk-toggle" => "{target:'.my-class'}" %>

OR

<%= g.label :self_estimation, :class => 'km-180-label', data: {uk_toggle: "{target:'.my-class'}"} %>

答案 2 :(得分:-1)

这样您就可以添加自定义属性。

<%= g.label :self_estimation, :class => 'km-180-label', :"data-uk-toggle" => "{target:'.my-class'}" %>