validation - rails how to validatie data params in method dose not updated, created -
i want validate 1 params in model method, can't found fit answers , please show me right way.
class user < activerecord::base validate :username, presence: true, length: 4..5, unique: true validate :email, presence: true, unique: true, format: {with: /\a[a-z0-9\.]+@([a-z]{1,10}\.){1,2}[a-z]{2,4}\z/} def self.get_post(id) # how call validate id ??? validates :id, numericality: true if id.valid? # true code else # false code end end def change_profile # how check validate user , email username.valid? email.valid? # some_code.... end end
thanks all.
you cannot use validates
there, can instead
def self.get_post(id) if id.is_a? numeric # true code else # false code end end
Comments
Post a Comment