From 2736d31c67210541407ae211e81baa7265fc647f Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 23 Feb 2017 15:46:12 -0600 Subject: [PATCH] dmail.rb: validate only on creation. to/from/title/body don't need to be revalidated after creation since they never change. --- app/models/dmail.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models/dmail.rb b/app/models/dmail.rb index c363cc0f5..8d8409f1f 100644 --- a/app/models/dmail.rb +++ b/app/models/dmail.rb @@ -1,12 +1,15 @@ require 'digest/sha1' class Dmail < ActiveRecord::Base - validates_presence_of :to_id - validates_presence_of :from_id - validates_format_of :title, :with => /\S/ - validates_format_of :body, :with => /\S/ - validate :validate_sender_is_not_banned - before_validation :initialize_from_id, :on => :create + with_options on: :create do + before_validation :initialize_from_id + validates_presence_of :to_id + validates_presence_of :from_id + validates_format_of :title, :with => /\S/ + validates_format_of :body, :with => /\S/ + validate :validate_sender_is_not_banned + end + belongs_to :owner, :class_name => "User" belongs_to :to, :class_name => "User" belongs_to :from, :class_name => "User"