Rails mongoid has field model validation

This can be done only with a custom method validation, Such as
     
    class Comment
       include Mongoid::Document
       include Mongoid::Timestamps 
       include ActiveModel::Validations
     
       validate :must_be_friends
     
       def must_be_friends
         errors.add(:base, 'Must be friends to leave a comment') if hash[:firstname].nil?
       end
    end

Comments

Post a Comment

Popular posts from this blog

Rails Kaminari - Ajax pagination

Rails Upgrading a project