Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Active Resource should warn about missing prefix value

#5631
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

Reported by Gaston Ramos · September 13th, 2010 @ 11:43 PM

State: committed
Milestone: 3.1
Assigned to: Mikel Lindsaar Mikel Lindsaar
Importance: Low

Activity

  1. Luciano G. Panaro
    Luciano G. Panaro

    +1

    Applied to both master and 3-0-stable and tests pass with patch and fail without it.

    September 14th, 2010 @ 12:51 AM

  2. Cesar
    Cesar

    +1 Applied and tested on edge

    September 14th, 2010 @ 01:07 AM

  3. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to open
    • Assigned user set to Santiago Pastorino
    • Importance changed from to Low

    September 14th, 2010 @ 04:32 AM

  4. Lake
    Lake

    +1 Applied cleanly and the tests pass on master.

    September 16th, 2010 @ 12:13 AM

  5. Lake
    Lake
    • Tag changed from activeresource, bug, edge, patch to activeresource, bug, edge, patch, verified

    September 16th, 2010 @ 06:17 PM

  6. Gaston Ramos
    Gaston Ramos
    • Title changed from ActiveResource::MissingPrefixParam proposal to Active Resource should warn about missing prefix value

    September 17th, 2010 @ 10:01 PM

  7. Gaston Ramos
  8. Mikel Lindsaar
    Mikel Lindsaar
    • Milestone set to 3.1
    • Assigned user changed from Santiago Pastorino to Mikel Lindsaar

    This is nice work. See my comments on the pull request.

    September 27th, 2010 @ 05:03 PM

  9. Gaston Ramos
    Gaston Ramos

    Mikel I'm sorry, I can't do a rebase against master because I removed my working copy and my local branch. I will do it right in my next patch.

    September 27th, 2010 @ 06:11 PM

  10. Gaston Ramos
    Gaston Ramos

    I did a new pull request without the merge commit:

    http://github.com/rails/rails/pull/57

    September 27th, 2010 @ 07:38 PM

  11. Santiago Pastorino
  12. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 9th, 2010 @ 10:03 PM

  13. Ryan Bigg
    Ryan Bigg

    Automatic cleanup of spam.

    October 21st, 2010 @ 03:38 AM

  14. bingbing