0 votes
in Ruby by
How would you validate that a project's name is not blank, is fewer than 50 characters, and is unique?

 A).

class Project

  validates :name, presence: true, length: { maximum: 50 }, uniqueness: true

end

 B).

class Project

  validate_attribute :name, [:presence, :uniqueness], :length => 1..50

end

 C).

class Project

  validate_before_save :name, [:presence, [:length, 50], :uniqueness], :length => 1..50

end

 D).

class Project

  validates_presense_of :name, :unique => true

  validates_length_of :name, :maximum => 50

end

1 Answer

0 votes
by
How would you validate that a project's name is not blank, is fewer than 50 characters, and is unique?

Correct answer is :- class Project

  validates :name, presence: true, length: { maximum: 50 }, uniqueness: true

end

Related questions

0 votes
asked Sep 3, 2022 in Ruby by DavidAnderson
0 votes
asked Sep 2, 2022 in Ruby by DavidAnderson
...