This project is archived and is in readonly mode.
ActiveResource support for singleton resources?
-
Duncan Mac-Vicar
One workaround that worked for me was to redefine element_path and collection_path to not include the id. THis solution was proposed as a workaround in some mailing list by people having the same problem.
def self.element_path(id, prefix_options = {}, query_options = nil)
prefix_options, query_options = split_options(prefix_options) if query_options.nil? # original: "#{prefix(prefix_options)}#{collection_name}/#{id}.#{format.extension}#{query_string(query_options)}" "#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}"end
collection_name singular def self.collection_path(prefix_options = {}, query_options = nil) prefix_options, query_options = split_options(prefix_options) if query_options.nil? # original: "#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}" "#{prefix(prefix_options)}#{collection_name}.#{format.extension}#{query_string(query_options)}" end
And then fix singularize collection_name.
Thanks to the behavior of ActiveResource, where for a singular resource Foo.find would go to /foos/.xml (because no :id) the workaround above makes find with no arguments to use /foo.xml and the result works fine with save and destroy. find(:all) does not work but this is expected.
May be a good improvement for ActiveResource would be to have a flag for singular resources and automatically use those element_path and collection_path in those cases.
I could contribute a patch for that, but I would like to know if the solution is ok.
-
josh
- Assigned user cleared.
-
Santiago Pastorino
- State changed from new to open
- Tag changed from 2.3, activeres, activeresource, active_resource, client, singleton to 23, activeres, activeresource, active_resource, client, singleton
- Importance changed from to
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino
- State changed from open to stale