Saurabh Shah Saurabh Shah - 1 year ago 91
Ruby Question

Equivalent of `exclusion` in sequel

What is the Sequel equivalent of "exclusion"?

For a simple example, in Active Record:

validates :subdomain, exclusion: { in: %w(www us ca jp),
message: "%{value} is reserved." }

How can this be written in Sequel?

Answer Source

Sequel doesn't provide the exclusion helper by default, but you could customize it yourself.

class Host < Sequel::Model
  def validate
    errors.add(:subdomain, "#{subdomain} is reserved.") if %w(www us ca jp).include?(subdomain)

See "Custom Validations" for more information.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download