Ruby on Rails Wednesday, August 1, 2012

Well, I added an inflector to fix this one.
And I had to strip the '.json' by adding this to the model:

class << self
    def element_path(id, prefix_options = {}, query_options = nil)
      prefix_options, query_options = split_options(prefix_options) if query_options.nil?
      "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}"
    end

    def collection_path(prefix_options = {}, query_options = nil)
      prefix_options, query_options = split_options(prefix_options) if query_options.nil?
      "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}"
    end
  end

but I have a lot of associated models to create for this API.  Where do I put something like this to override ALL instances of the ActiveResource element_path and collection_path calls?


On Jul 31, 2012, at 4:47 PM, Tom Allison wrote:

Ran into a great problem.  REST, as it's implimented via Rails, identifies the URL as a plural in every case.  So you would retrieve a single issue through /issues/<insert key here>.  This seems to be technically incorrect.

I find other (non-Rails) documentation talking about this being singular for getting a single issue and plural for a list.

And this is also how the site I'm trying to access is configured.  Which means that every time I try to GET a single issue the ActiveResource is calling for /issues/<insert key here> instead of the correct /issue/<insert key here>.

Does anyone know of a way to workaround this problem using ActiveResource?


Maybe I should ask if anyone else agrees that this is a problem in the implementation of the REST api in ActiveResource?


No comments:

Post a Comment