Skip to content

Instantly share code, notes, and snippets.

@kernow
Created November 19, 2010 13:07
Show Gist options
  • Save kernow/706491 to your computer and use it in GitHub Desktop.
Save kernow/706491 to your computer and use it in GitHub Desktop.
Mongoid criteria problem?
# I would expect all of the following to return the same results
# Works as expected
Article.find(:first, :conditions => { :slug => 'blah', :published => true })
# On latest beta gem errors with ArgumentError: wrong number of arguments (2 for 0..1)
# Works on latest github master commi
Article.where(:published => true).find(:first, :conditions => { :slug => 'blah' })
# On latest beta gem erros with ArgumentError: wrong number of arguments (2 for 0..1)
# Works on latest github master commi
Article.published.find(:first, :conditions => { :slug => 'blah' })
# On latest beta gem errors with ArgumentError: wrong number of arguments (1 for 0)
# Works on latest github master commi
Article.published.first(:conditions => { :slug => 'blah' })
# Works on latest github master commit
Article.published.where(:slug => 'blah').first
# Article Model
class Article
include Mongoid::Document
include Mongoid::Timestamps
field :title
field :slug
field :body
field :published, :type => Boolean, :default => false
validates_presence_of :title, :body
before_save :set_slug
scope :published, :where => { :published => true }, :order_by => :created_at.desc
def set_slug
self.slug = title.parameterize
end
def to_param
slug
end
end
@thomasv314
Copy link

@kernow did you ever find the solution to this problem?

@kernow
Copy link
Author

kernow commented Mar 22, 2012

I believe this was fixed in a later version

@thomasv314
Copy link

:'(

Having the same issue on 2.4.7.

Any chance you were using the mongoid_slug gem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment