Jay Pangmi wrote:
> even though the
> children field is empty and user select the family rate claim check box
> it gets validated ok and the details get saved which actually shouldn't
> happen. so, how can i improve tat code to eliminate this bug? thanks..
See if you're receiving an empty parameter in params[:children]...
Raqther than params[:children].nil?, try .empty?
def validate_input_rules
msg = ''
if self.children.empty?
if self.family_claim == '1'
msg = No family rate without children.'
end
else
if self.parents.to_i + self.children.to_i > 8
msg = 'Maximum 8 people in a group.'
end
end
if self.family_claim != '1'
total = (((self.parents.to_i + self.children.to_i) * 4.85)
* self.nights.to_i)
else
total = (19.4 * self.nights.to_i)
end
return msg
end
I've been bitten by the nil vs empty enough times in the past...
and check that code to make sure I didn't fubar something...
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---