How to raise a validation error in Rails after save
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
|# This probably isn't a good thing to want to do, but it came up for me,|
|# so in the spirit of helping others with weird problems (and because this|
|# seems to be documented almost nowhere):|
|errors.add(:something, "some failure happened.")|
Jan 8, 2021
Class: RuboCop::Cop::Style::RaiseArgscop with
rubocop. Any hints?
raise ActiveRecord::RecordInvalid, user if user.invalid? and no rubocop error
Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Still helpful in October 2020. We were on Rails 6 and we thought "oh, but it's all ActiveRelation now" but nope, ActiveRelation inherits from ActiveRecord::Base, and this is still the correct error class. Thank you!