validation of drop down menu

How best to do this?

I have the following code:

<%= collection_select(:country, :id, @country_list, :id, :country_name,
options ={:prompt => "-- Select a country --"}, :class =>"country") %>

How can I ensure that this the is validated correctly?

I have tried validates_prescence_of, but does not seem to work when I
select an actual country - it says:

Country can't be blank

Any idea what this could mean or how should I do this?

How best to do this?

I have the following code:

<%= collection_select(:country, :id, @country_list, :id, :country_name,
options ={:prompt => "-- Select a country --"}, :class =>"country") %>

How can I ensure that this the is validated correctly?

I have tried validates_prescence_of, but does not seem to work when I
select an actual country - it says:

Country can't be blank

Any idea what this could mean or how should I do this?

It means that you have said validates_presence_of country and it is
blank, so is not present, so the validation fails. Look in
development.log to see what values are being passed to the controller.
If necessary use ruby-debug to break in to the controller at the save
to see what you have put into the record being saved. See the Rails
Guide on debugging if you do not know how to do this.

Colin

Thanks Colin,

The development log looks like its going to be useful in the future.
This is what I get for the country:

country"=>{"id"=>"6"}, so it looks like a value has been selected, but
the validation still fails...

Colin Law wrote:

surely something seems amiss in the drop down control??

Why would you think that if you can see the country id being passed
into the controller?

Look at your controller code. Use ruby-debug as suggested, or add
some debugging log statements.

Hassan Schroeder wrote:

Most likely. You'll know for sure if you follow the suggestions to debug
your controller :slight_smile: