Rails 3 - Custom Validation

后端 未结 2 1779
庸人自扰
庸人自扰 2021-02-01 04:50

I\'m somewhat confused by my options for custom validations in Rails 3, and i\'m hoping that someone can point me in the direction of a resource that can help with my current is

2条回答
  •  再見小時候
    2021-02-01 05:23

    you can use custom validation method, as described here:

    class Vehicle < ActiveRecord::Base
      validate :model_year_valid_for_trim
    
      def model_year_valid_for_trim
        if #some validation code for model year and trim
          errors.add(:model_years, "some error")
        end
      end
    
    end
    

提交回复
热议问题