I not using ActiveRecords rather using ActiveModel to validate form data. I am stuck into some point where i needed to validate a form field depending on a radio button value.
My model is
class Payment
include ActiveModel::Model
attr_accessor :method_id, :crad_name
validates_presence_of :card_name, :if => :method_type?
private
def method_type?
self.method_id == 1
end
end
Here, method_id = 1 for credit card and method_id = 2 for bank
That does not validate the form field and does not show any error either.
I have searched in google and got some valuable stuff for here Rails - How to validate a field only if a another field has a certain value?
But it does not work in this case. Thanks in advance for your suggestion and help