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

Popular posts from this blog

Rails Kaminari - Ajax pagination

Rails 4, MySQL, and Emoji (Mysql2::Error: Incorrect string value: '\xF0\x9F\x8C\x9D')