RailsCasts Pro episodes are now free!

Learn more or hide this

Guilloteau Romain's Profile

GitHub User: colderis

Comments by Guilloteau Romain


Late response but it can be usefull for someone else.

There's no "LIKE" command for MongoDB, you can perform a search with a regex.

Project.where(name: /yard/i)

But as always there's already some gem that do the work for you :
For Keyword search : https://github.com/mauriciozaffari/mongoid_search
For FullText search : https://github.com/artsy/mongoid_fulltext


For Mongoid

def self.current(except = nil)
  now = Time.current
  result = where(:starts_at.lte => now, :ends_at.gte => now)
  result = result.where(:id.nin => except) if except.present?

lte : less than or equal
gte : greater than or equal
nin : not in

I really love the Mongoid syntax.


Be careful with simple_form

Took me awhile to discover that you can't login if your form is built with simple_form.
My sessions controller is in an admin namespace and the builder gave me "/admin/sessions[password]".