Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow ActiveResource to work with non-generated ids [#5660 state:reso…
…lved] This commit updates new? so that it knows whether or not the record was actually new or not, and doesn't rely solely on the presence of id. This enables the ability to set a custom primary_key that is not autogenerated by the server. Signed-off-by: José Valim <jose.valim@gmail.com>
- Loading branch information
Showing
5 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# turns everyting into the same object | ||
class AddressXMLFormatter | ||
include ActiveResource::Formats::XmlFormat | ||
|
||
def decode(xml) | ||
data = ActiveResource::Formats::XmlFormat.decode(xml) | ||
# process address fields | ||
data.each do |address| | ||
address['city_state'] = "#{address['city']}, #{address['state']}" | ||
end | ||
data | ||
end | ||
|
||
end | ||
|
||
class AddressResource < ActiveResource::Base | ||
self.element_name = "address" | ||
self.format = AddressXMLFormatter.new | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class SubscriptionPlan < ActiveResource::Base | ||
self.site = "http://37s.sunrise.i:3000" | ||
self.element_name = 'plan' | ||
self.primary_key = :code | ||
end |