Guest User

Untitled

a guest
Aug 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. How do I change an ActiveRecord from marked to be saved to make sure it does not get saved, from within the model itself?
  2. before_save :ignore_new_delete_exisiting_if_blank(self.attribute)
  3.  
  4. def ignore_new_delete_exisiting_if_blank(attribute)
  5. self.do_not_save_me! if attribute.blank?
  6.  
  7. #what is that magic "do_not_save_me" method?
  8. #Is there such thing, or something to achieve the same thing?
  9. end
  10.  
  11. def ignore_new_delete_exisiting_if_blank_attribute
  12. if attribute.blank?
  13. errors.add(:base, "Not allowed to save if attribute is blank.")
  14. end
  15. end
  16.  
  17. validates_presence_of :attribute
  18.  
  19. accepts_nested_attributes_for :posts, :reject_if => proc { |attributes| attributes['title'].blank? }
  20.  
  21. def ignore_new_delete_exisiting_if_blank(attribute)
  22. attribute.present?
  23. end
Add Comment
Please, Sign In to add comment