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