Created
December 2, 2008 18:58
-
-
Save pol/31220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Data returned when you go to http://localhost:8080/Class/Class ## | |
({"id":"Class", | |
"data":{"$ref":""}, | |
"description":"Classes in the system, every class has a table of the instances of the class", | |
"properties":{ | |
}, | |
"prototype":{"$ref":"../s$0"} | |
}) | |
## ActiveResource Model ## | |
class Persevere < ActiveResource::Base | |
self.site = 'http://localhost:8080' | |
self.element_name = 'Class' | |
self.format = :json | |
# overriding element_path to omit the extension and make the collection_name singular | |
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.classify}/#{id}#{query_string(query_options)}" | |
end | |
# overriding the collection_path to omit the extension and make the 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.classify}#{query_string(query_options)}" | |
end | |
end | |
## Console Output Without Monkeying with ActiveResource ## | |
~/Rails/persevere $ sc | |
Loading development environment (Rails 2.2.2) | |
>> Persevere.find('Class') | |
TypeError: allocator undefined for Data | |
from /Users/pol/Rails/persevere/vendor/rails/activeresource/lib/active_resource/base.rb:950:in `new' | |
from /Users/pol/Rails/persevere/vendor/rails/activeresource/lib/active_resource/base.rb:950:in `load' | |
from /Users/pol/Rails/persevere/vendor/rails/activeresource/lib/active_resource/base.rb:941:in `each' | |
from /Users/pol/Rails/persevere/vendor/rails/activeresource/lib/active_resource/base.rb:941:in `load' | |
from /Users/pol/Rails/persevere/vendor/rails/activeresource/lib/active_resource/base.rb:653:in `initialize' | |
from /Users/pol/Rails/persevere/vendor/rails/activeresource/lib/active_resource/base.rb:601:in `new' | |
from /Users/pol/Rails/persevere/vendor/rails/activeresource/lib/active_resource/base.rb:601:in `instantiate_record' | |
from /Users/pol/Rails/persevere/vendor/rails/activeresource/lib/active_resource/base.rb:593:in `find_single' | |
from /Users/pol/Rails/persevere/vendor/rails/activeresource/lib/active_resource/base.rb:521:in `find' | |
from (irb):1 | |
## Modify vendor/rails/activeresource/lib/active_resource/base.rb with the following inserted at Line 942 ## | |
key = :pdata if key.to_s == 'data' | |
## New Console Output After Monkeying With ActiveResource ## | |
~/Rails/persevere $ sc | |
Loading development environment (Rails 2.2.2) | |
>> Persevere.find('Class') | |
=> #<Persevere:0x243a9e8 @attributes={"pdata"=>#<Persevere::Pdata:0x2428e28 @attributes={"$ref"=>""}, @prefix_options={}>, "id"=>"Class", "description"=>"Classes in the system, every class has a table of the instances of the class", "prototype"=>#<Persevere::Prototype:0x242bfb0 @attributes={"$ref"=>"../s$0"}, @prefix_options={}>, "properties"=>#<Persevere::Properties:0x2426b64 @attributes={}, @prefix_options={}>}, @prefix_options={}> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment