I have to deal with an unusual problem when checking for an association in a derived class.
Class Contact < ActiveRecord::Base has_and_belongs_to_many :things end Class SubContact < Contact # validates_presence_of :things validate :must_have_things def must_have_things if things.blank? errors.add("Must select things") end end end
In the SubContact class SubContact I try to check for things, but nothing works. I have tried both custom and built-in validators. How can I achieve this?
SubContact
add need an attribute. Try using:
add
errors.add(:base, "Must not be blank")
In this case, it is a base class, but it can be any other attribute. Specify the attribute name of the SubContract or :base class.
:base
Source: https://habr.com/ru/post/1237721/More articles:most unexpected conversion - c ++Rails - could not find jquery_ujs file with type 'application / javascript' - ruby | fooobar.comThe search bar is disabled when using the UISearchController with the UITabBarController inside the UINavigationController - iosStop fixed background image from scrolling at a certain height - javascriptHow to query AWS DynamoDB in python? - pythonJava - is dropped into the interface, and then it turns out what a cast type is - javaSwitch measured connection - windowsLoading a multi-page file: oversize in spring error returning to original JSON message - springRecommended way to handle multiple malloc errors in one function in C - cBootstrap 3 not working in symfony3 - cssAll Articles