How can I validate a radio button?

前端 未结 1 450
轮回少年
轮回少年 2021-01-22 16:46

I have a radio button in my Rails application:

.<% @votes.each do |vote| %>

   .<%= radio_button_tag \"escolha\", \"#{vote.id}\" %>

.<% end %>         


        
相关标签:
1条回答
  • 2021-01-22 17:12

    In your votes class do something similar to this:

        class Myvotes < ActiveRecord::Base
          validates :votes, :presence => true
        end
    

    Please refer to the 8.2 Validations section of the Rails release notes, this tutorial, and the Rails API documentation.

    0 讨论(0)
提交回复
热议问题