This project is archived and is in readonly mode.

#5631 ✓committed
Gaston Ramos

Active Resource should warn about missing prefix value

Reported by Gaston Ramos | September 13th, 2010 @ 11:43 PM | in 3.1

require 'active_resource'

class Comment < ActiveResource::Base
  self.site = "http://someip.com/posts/:post_id/"
end

Comment.find(1)

#=> ActiveResource::ResourceNotFound: Failed.  Response code = 404.  Response message = Not Found.

This exception is not specific enough because here the first problem is that we didn't pass the :post_id param, see:

Comment.element_path(1)
# => # => /posts//comments/1.xml

and sometimes this situation could be confusing, the resource will never be found if you don't provide the prefix_params, so prefix_params should be a required param IMO.

I attached a patch that adds a new exception ActiveResource::MissingPrefixParam and works like this:

class Comment < ActiveResource::Base
  self.site = "http://someip.com/posts/:post_id/"
end

Comment.find(1)
# => ActiveResource::MissingPrefixParam: post_id prefix_option is missing

Comment.element_path(1)
# => ActiveResource::MissingPrefixParam: post_id prefix_option is missing

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Attachments

Pages