Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1171

undefined method `scoped' for #<Poster:0x007fa7d691c460>

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.2.1
    • Affects Version/s: None
    • Component/s: None
    • None

      In my Rails (3.0.10) application, I'm using mongoid (2.1.8) and I'm encountering this exception:

      undefined method `scoped' for #<Poster:0x007fa7d691c460>

      In my application, I can found a Poster by the id or by a composed name like "composed-name+with+345".
      When I use the composed name my scope is working well, but when I use the BSON::ObjectId, it fail with the exception.

      So, here is my scope where the exception come from:

      scope :from_id_or_string, ->(poster_id_or_string) {
        if BSON::ObjectId.legal?(poster_id_or_string)
          Poster.find(poster_id_or_string)
        else
          Poster.for_ticket(Ticket.parse(poster_id_or_string))
        end
      }
      

      When I send the string "name+and+number-1234", the if BSON::ObjectId.legal?(poster_id_or_string) line return false then go to the else and use the for_ticket scope etc... and all work fine.

      When I send the string "4e4ff0533ea9403ce300007f", the if BSON::ObjectId.legal?(poster_id_or_string) line return true then go to the Poster.find(poster_id_or_string) line and then I got the exception.

      If I do, before the Poster.find this:

      puts Poster.find(poster_id_or_string).inspect

      it show me the Poster I'm looking for.

      Other thing I've tried is to use Poster.where(:_id => poster_id_or_string). It was working in some cases but not all.

            Assignee:
            Unassigned Unassigned
            Reporter:
            zedtux Guillaume Hain
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: