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?


  1. I like your post very much. It is very much useful for my research. I hope you to share more info about this. Keep posting ruby certification


Post a Comment

Popular posts from this blog

Rails Kaminari - Ajax pagination

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