ambition/app/models/share.rb

38 lines
999 B
Ruby

class Share < ActiveRecord::Base
validates :content, presence: true
validates :project_id, presence: true
validates :user_id, presence: true
validate :share_has_atleast_one_character
validate :user_exists,on: :create
validate :project_exists,on: :create
private
def share_has_atleast_one_character
tmp = content.strip
if tmp.length < 1
errors[:content] = "share content should has at least one character"
end
end
def user_exists
user = User.find_by(id: user_id)
if user == nil
errors[:user] = "user belong to Share is not exist"
end
end
def project_exists
project = Project.find_by(id: project_id)
if project == nil
errors[:project] = "user belong to Share is not exist"
end
end
end