ã¯ããã« errors.addâ¦â¦ã®æ¸ãæ¹ãããå¿ãã¦ãã¾ãã®ã§åå¿é²ã æ¡ä»¶ Projectã¢ãã«ã¨Genreã¢ãã«ãhas_and_belongs_to_manyã§ä¸éãã¼ãã«ãéãã¦ã¢ã½ã·ã¨ã¼ã·ã§ã³ããã¦ããã projectãcreateããã¨ãã該å½ã®projectã®Genreãç»é²ãã¦ããã erros.addãvalidateã«è¨è¿°ãã class Project < ApplicationRecord has_and_belongs_to_many :genres validates :name, presence: true, length: { maximum: 200 } ã» ã» ã» validate :has_genres? def has_genres? errors.add(:genres, "ãé¸ãã§ãã ãã") if self.genres.blank? e
{{#tags}}- {{label}}
{{/tags}}