DEV Community

roeihaviv
roeihaviv

Posted on

'validate' vs. 'validates'

Validate let's you create your own validates. Example:

--

validate :users_cant_follow_themselves

def users_cant_follow_themselves
if sender_id == recipient_id
errors.add(:sender_id, "can't follow themselves")
end

--

Validates - define a table column and then choose from limited options to define the validation. Example:

--

validates :recipient_id, uniqueness: { scope: :sender_id, message: "already requested" }

Top comments (1)

Collapse
 
citronbrick profile image
CitronBrick

Please indent your code.
Also, you can enable syntax highlighting for ruby.

(triple backtick) ruby

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay