Validates_presence_of :if

Hi
I have a table service_desk_resolution_codes as below
id | name
----±-----------------
1 | << Select Any >>
2 | Resolution 1
3 | Resolution 2

And I am using this to submit resolution code in select box in a
view.What i need is if the user select << Select Any >> a validation
check is done says that this is not acceptable select any resolution
code…(Currently i have implemented it with a javascript).But how can i
do it in the model ServiceDeskResolution…Is the following way correct
validates_presence_of :service_desk_resolution_code_id, :if
=>“service_desk_resolution_code_id==1”

Surely this is error…But how can I do it in correct way

service_desk_resolution_code_id is a field of the table
service_desk_resolutions
Thanks in advance
Sijo

Rather than putting your prompt text in the table, get rid of it, and
when you need to provide a drop-down for resolution code use the :prompt
argument to have rails insert the prompt for you. I believe that will
allow you to just put a “validates_presence_of :resolution_code” in the
appropriate model & rails will “know” not to accept the prompt value.

So your call to collection_select might look like:

<%= f.collection_select(:resolution_code,
ResolutionCode.find(:all),
:id,
:name,
{:prompt => ‘Please select a resolution’}
) %>

HTH,

-Roy

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