Renato Shumi
Renato Shumi

Reputation: 318

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.

Upvotes: 2

Views: 1350

Answers (1)

uday
uday

Reputation: 8710

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.

Upvotes: 4

Related Questions