由于某种原因,radio_button_tag
块中的form_tag
将不遵守已检查的参数。我已尝试true
,:checked => checked
,checked: true
以及所有不同的组合。
这是我的代码,第三个参数为true
<%= radio_button_tag :metric_type, :followers_count, true, :class => 'chart-radio-icon' %>
<%= label :metric_type, 'Followers', :class => 'chart-radio-label chart-radio-metrics-social' %>
radio_button_tag 'color', "green", true, class: "color_input"
# => <input checked="checked" class="color_input" id="color_green" name="color" type="radio" value="green" />
然而,在DOM中它呈现为:
<input type="radio" name="metric_type" id="metric_type_followers_count" value="followers_count">
==更新=====================
ruby -v ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin15]
rails -v Rails 5.0.1
注意 - 我还没有在这些类上设置任何样式。
<div>
<%= form_tag url_for(controller: 'analytics', action: 'mega_chart'), method: :get, remote: true do %>
<p class='chart-legend-header'>Social</p>
<%= radio_button_tag :metric_type, :followers_count, :class => 'chart-radio-icon' %>
<%= label :metric_type, 'Followers', :class => 'chart-radio-label chart-radio-metrics-social' %>
<%= radio_button_tag :metric_type, :views_count, :class => 'chart-radio-icon' %>
<%= label :metric_type, 'Views', :class => 'chart-radio-label chart-radio-metrics-social' %>
<%= radio_button_tag :metric_type, :comments_count, :class => 'chart-radio-icon' %>
<%= label :metric_type, 'Comments', :class => 'chart-radio-label chart-radio-metrics-social' %>
<%= radio_button_tag :metric_type, :shares_count, :class => 'chart-radio-icon' %>
<%= label :metric_type, 'Shares', :class => 'chart-radio-label chart-radio-metrics-social' %>
<%= radio_button_tag :metric_type, :dislikes_count, :class => 'chart-radio-icon' %>
<%= label :metric_type, 'Dislikes', :class => 'chart-radio-label chart-radio-metrics-social' %>
<%= radio_button_tag :metric_type, :media_count, :class => 'chart-radio-icon' %>
<%= label :metric_type, 'Posts', :class => 'chart-radio-label chart-radio-metrics-social' %>
<p class='chart-legend-header'>Options</p>
<%= radio_button_tag :date_range, 30.days.ago, true, :class => 'chart-radio-icon' %>
<%= label :date_range, '30 Days', :class => 'chart-radio-label chart-radio-options-date' %>
<%= radio_button_tag :date_range, 90.days.ago, :class => 'chart-radio-icon' %>
<%= label :date_range, '90 Days', :class => 'chart-radio-label chart-radio-options-date' %>
<%= radio_button_tag :benchmark_type, 'daily_gain', true, :class => 'chart-radio-icon' %>
<%= label :benchmark_type, 'Daily Gain', :class => 'chart-radio-label chart-radio-options-benchmark' %>
<%= radio_button_tag :benchmark_type, 'total', :class => 'chart-radio-icon' %>
<%= label :benchmark_type, 'Total', :class => 'chart-radio-label chart-radio-options-benchmark' %>
<%= submit_tag 'Refresh Chart', :id => 'chart-submit' %>
<% end %>
</div>
答案 0 :(得分:0)
在进一步检查HTML后,我发现所有的单选按钮都呈现为checked="checked"
所以我将每个第三个参数标记为false
,除了我想要的那个真实!
<%= radio_button_tag :metric_type, :followers_count, true, :class => 'chart-radio-icon' %>
<%= label_tag(:metric_type_followers_count, 'Followers', :class => 'chart-label chart-label-social') %>