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?

On 4 August 2010 15:37, disruptive tech [email protected] wrote:

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 L. wrote:

On 4 August 2010 15:37, disruptive tech [email protected] wrote:

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

On Wed, Aug 4, 2010 at 8:51 AM, disruptive tech [email protected]
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 S. ------------------------ [email protected]
twitter: @hassan

Hassan S. wrote:

On Wed, Aug 4, 2010 at 8:51 AM, disruptive tech [email protected]
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 S. ------------------------ [email protected]
twitter: @hassan

is it formatted in the correct way?
with the country"=>{“id”=>“6”}, should it be: country"=>“6”???

On Thu, Aug 5, 2010 at 3:13 AM, disruptive tech [email protected]
wrote:

is it formatted in the correct way?

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


Hassan S. ------------------------ [email protected]
twitter: @hassan

surely something seems amiss in the drop down control??

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs