Answers for "rails generate model options"

0

rails generate model with options

class Article < ApplicationRecord
  has_many :comments

  validates :title, presence: true
  validates :body, presence: true, length: { minimum: 10 }

  VALID_STATUSES = ['public', 'private', 'archived']

  validates :status, inclusion: { in: VALID_STATUSES }

  def archived?
    status == 'archived'
  end
end
Posted by: Guest on February-16-2022

Code answers related to "rails generate model options"

Browse Popular Code Answers by Language