简体   繁体   中英

How can I validate a radio button?

I have a radio button in my Rails application:

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

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

.<% end %>

I want to make a java-script code that validates this when no option is chosen.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM