validates_presence_of if condition on rails 3.2 and mongoid + simple_form
ruby-on-rails, ruby-on-rails-3, validation
Solution
The fix for me to this question is the next code:
validates :shipping_cost, :shipping_cost_anywhere, :presence => true, :if => :shipping?
Thank you to all for your help but any answer has worked for me. thanks!
Problem
I want validate presence of these 2 attributes `:shipping_cost` and `:shipping_cost_anywhere` if the attribute `:shipping` is equal to `true`. and If I have this in my model but not working fine for me: ``` validates_presence_of :shipping_cost, :shipping_cost_anywhere, :allow_blank => "true" if :shipping == "true" ``` this is my :shipping attribute: ``` field :shipping, :type => Boolean, :default => "false" ``` How can I do it? Thank you! Edited. I'm using mongoid and simple_form gems