Home > Enterprise >  How to validate specific word in Rails?
How to validate specific word in Rails?

Time:12-12

I'd like to validate a specific words in my book.rb models words:

book_name = "Pencil", "Paper", "Toy"

if the user does not enter any of those fields then it will be invalid

CodePudding user response:

You can use following AR validation https://guides.rubyonrails.org/active_record_validations.html#inclusion

 validates :book_name, inclusion: { in: %w(Pencil Paper Toy) }
  • Related