validation - Rails: How do I use validates_presence_of based on data in an associated class -


i have:

class < activerecord::base   attr_accessible :detailed_info    belongs_to b end  class b < activerecord::base   attr_accessible :requires_detail_in_a_of_type, :basic_detail end 

i want validation looks @ a, , verifies :detailed_info present iff associated b.requires_detail_in_a_of_type == "some value".

i can write write validate method, extending activerecord::validator, necessary? straightforward:

validates_presence_of :detailed_info, if: lambda { self.b.requires_detail_in_a_of_type = "some value" } 

isn't working (with, or out "self.").


Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -