Associating label and radio button in Rails

后端 未结 2 1471
孤街浪徒
孤街浪徒 2021-01-02 01:24

I\'m using Rails 2.3.8. My code:

<%= f.radio_button :status, \"draft\" %>
<%= f.label :status, \"Draft\" %>
<%= f.radio_button :status, \"publ         


        
相关标签:
2条回答
  • 2021-01-02 02:00

    Try this

    <%= f.radio_button :status, "draft" %>
    <%= f.label :status, "Draft", :value => "draft" %>
    <%= f.radio_button :status, "published" %>
    <%= f.label :status, "Published", :value => "published" %>
    
    0 讨论(0)
  • 2021-01-02 02:26

    This worked for me, where I was looping through plans:

    <% @plans.each do |plan| %>
        <%= radio_button_tag :plan_id, plan.id %> 
        <%= label_tag 'plan_id_' + plan.id.to_s, plan.name %>
    <% end %>
    
    0 讨论(0)
提交回复
热议问题