1

I am developing a Sinatra server that can accept calls from ActiveResource, but can"t determine how to identify Get calls specificying :first or :last.

In Rails 3

User.find(:first)  => localhost.com/user.xml
User.find(:last)  => localhost.com/user.xml

This works exactly as it should according to the examples in the ActiveResource documentation.

It is clear what path they request (the same one), but it is not clear what happens to the :first or :last elements. I can not find them in the request object on the Sinatra server. Does anyone know what happened to those references?

Thanks for your help.

Scott
  • 330
  • 3
  • 15
  • One thing I learned in testing my app is that Sinatra needs the hash object responses to :first, :last, :all, all wrapped in a array, otherwise an error will be generated in Rails. – Scott Aug 02 '11 at 20:45

1 Answers1

0

Code from ActiveResource library

  def find(*arguments)
        scope   = arguments.slice!(0)
        options = arguments.slice!(0) || {}

        case scope
          when :all   then find_every(options)
          when :first then find_every(options).first
          when :last  then find_every(options).last
          when :one   then find_one(options)
          else             find_single(scope, options)
        end
      end

last and first just methods from Enumerable module

Fivell
  • 11,829
  • 3
  • 61
  • 99