Rails validation - maximum database entries -


i have rails project, using active record , wondering if there validation helper max number of individual entries. example, if had form submission , wanted, 2, , wanted first 2 persisted table, how this?

i have read manual , had @ numericality etc it's not i'm looking for. have tried write own validation method in model, assuming there validation helper makes easier:

  def validatepassengernumber      if self.passengers.length > 2       # unsure on how refuse new data access database     end   end 

add error base after check return true, , prohibit save database.

 def validate_passenger_number              self.errors.add(:base, "exceed maximum entry") if self.passengers.length > 2  end  

call custom validation in respective model.

  validate :validate_passenger_number, on: :create 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -