I have following code for radio options in loop.
t
I wish to have the first radio option default selected. How can I do this?
<% @this.each do |p| %>
<div class="radio_button_with_text">
<%=radio_button "this" ,"name",p.name ,:onclick=>"save_package(#{p.id})"%>
<p class="radioText"><%= p.name %></p>
</div>
<% end %>
is not wokring for me.
答案 0 :(得分:1)
试试这个例子:
<% @products.each do |product| %>
<div class="radio_button_with_text">
<%=radio_button_tag product.name ,:id, @products.first == product, class: "save_package", "data-id" => product.id %>
<p class="radioText"><%= product.name %></p>
</div>
<% end %>
$(document).on('click', '.save_package', function(e) {
save_package(this.attr("data-id"));
});