Sha256: 3ec40df8e132b2707bcfbe0c48b8d868669a63f75a188c1d735c6b7492bd5e7c
Contents?: true
Size: 790 Bytes
Versions: 2
Compression:
Stored size: 790 Bytes
Contents
class BlogPost include Mongoid::Document field :title field :content field :locale index :title index :locale before_validation :assign_current_locale validates :title, :presence => true validates :locale, :presence => true embeds_many :comments, :class_name => "Blogs::Comment" scope :ordered, desc(:_id) scope :in_current_locale, lambda { where(:locale => I18n.locale.to_s) } class << self def search(keyword) in_current_locale.where("this.title.match(/#{keyword}/i) || this.content.match(/#{keyword}/i)") end def search_embedded(keyword) in_current_locale.where("comments.content" => Regexp.new(keyword)) end end private def assign_current_locale self.locale ||= I18n.locale.to_s end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rspec_extensions_collection-0.0.4 | spec/models/blog_post.rb |
rspec_extensions_collection-0.0.3 | spec/models/blog_post.rb |