02-11-2011, 06:09 PM
Ben, tu ajoutes un validateur sur le receiver au niveau de ton modèle :
class Message < ActiveRecord::Base
belongs_to :author, class_name: "User"
belongs_to :receiver, class_name: "User"
validates_presence_of :author, :receiver, :title, :body
validate :receiver_exists
def receiver_exists
errors[:receiver_id] << :inclusion unless User.exists?(id: receiver_id)
end
end