Validate the number of has_many items in Ruby on Rails

前端 未结 3 1062
走了就别回头了
走了就别回头了 2020-11-28 06:48

Users can add tags to a snippet:

class Snippet < ActiveRecord::Base

  # Relationships
  has_many :taggings
  has_many :tags, :through => :taggings
  b         


        
3条回答
  •  心在旅途
    2020-11-28 07:10

    A better solution has been provided by @SooDesuNe on this SO post

    validates :tags, length: { minimum: 1, maximum: 6 }
    

提交回复
热议问题