T
Tahura Chaudhry
I am using
Ruby Version: 1.8.4
Rails Version: 1.2.2
I have an issue regarding validation of a boolean field in my
applicaiton.
On the UI, I had to show a dropdown with options: "yes", "no" and ""
(blank)
My HTML view contains:
<%= select 'guest', 'attending', [['Yes', true], ['No', false]],
{:include_blank => true, :custom_label => 'Will you be attending?'} %>
The view is rendered correctly.
The validation for this dropdown requires that blank is invalid. Only
"yes" or "no" are valid.
My Model (guest.rb) contains:
validates_inclusion_of
attending, :in => [true, false])
The Issue is:
When I select blank in the UI dropdown component and post the form, the
validation succeeds and when the form is redisplayed 'No' is selected in
the dropdown. I see that in the database (MySQL) attending column,
false gets saved in that column.
How do I make validation to fail when blank is selected in the dropdown.
thanks,
Ruby Version: 1.8.4
Rails Version: 1.2.2
I have an issue regarding validation of a boolean field in my
applicaiton.
On the UI, I had to show a dropdown with options: "yes", "no" and ""
(blank)
My HTML view contains:
<%= select 'guest', 'attending', [['Yes', true], ['No', false]],
{:include_blank => true, :custom_label => 'Will you be attending?'} %>
The view is rendered correctly.
The validation for this dropdown requires that blank is invalid. Only
"yes" or "no" are valid.
My Model (guest.rb) contains:
validates_inclusion_of
The Issue is:
When I select blank in the UI dropdown component and post the form, the
validation succeeds and when the form is redisplayed 'No' is selected in
the dropdown. I see that in the database (MySQL) attending column,
false gets saved in that column.
How do I make validation to fail when blank is selected in the dropdown.
thanks,