Revisions made by tamc2 up to 18:23 Fri 30 Jun 2006
Note, if you wish to edit or undo these revisions, please follow the links from here. You cannot do it from here, becuase someone may have edited the page more recently and because you may need a password to edit the page.
18:23 Fri 30 Jun 2006
52. You can then get the object, as expected:- 52. You can then get an object:
- 58.
- 59. There is an error if you try and @find(:all)@ and no objects exists.
18:05 Fri 30 Jun 2006
91. [[ActiveResource::Base => http://dev.rubyonrails.org/browser/trunk/activeresource/lib/active_resource/base.rb#L54]]- 91. [[ActiveResource::Connection => http://dev.rubyonrails.org/browser/trunk/activeresource/lib/active_resource/connection.rb#L54]]
18:04 Fri 30 Jun 2006
2. Last updated 22:45 BST Fri 30 June.- 2. Last updated 23:04 BST Fri 30 June.
- 71.
- 72. I made this changes to get a create function:
- 73.
- 74. [[ActiveResource::Base => http://dev.rubyonrails.org/browser/trunk/activeresource/lib/active_resource/base.rb#L65]]
- 75. <pre>
- 76. <code>
- 77. def save
- 78. id ? update : create
- 79. end
- 80. </code>
- 81. </pre>
- 82.
- 83. <pre>
- 84. <code>
- 85. def create
- 86. attributes["id"] = connection.post(self.class.collection_path, to_xml)
- 87. end
- 88. </code>
- 89. </pre>
- 90.
- 91. [[ActiveResource::Base => http://dev.rubyonrails.org/browser/trunk/activeresource/lib/active_resource/base.rb#L54]]
- 92. <pre>
- 93. <code>
- 94. def post(path, body)
- 95. response = request(:post, path, body)
- 96. return response['Location'][/\/([^\/]*?)$/,1] # The id
- 97. end
- 98. </code>
- 99. </pre>
17:47 Fri 30 Jun 2006
2. Last updated 22:45 BST Fri 30 June- 2. Last updated 22:45 BST Fri 30 June.
17:45 Fri 30 Jun 2006
2. Last updated 22:05 BST Fri 30 June- 2. Last updated 22:45 BST Fri 30 June
59. h2. Put / Post / Update- 59. h2. Put / Update
- 67.
- 68. h2. Post / Create
- 69.
- 70. Creating a record doesn't work, as @Person.save@ currently goes straight to the put method.
17:44 Fri 30 Jun 2006
0. content moved to [[]]- 0. h1. Early experiences with Active Resource
- 1.
- 2. Last updated 22:05 BST Fri 30 June
- 3.
- 4. At the recent RailsConf David Heinemeier Hansson announced his ideas for an active resource library in [[rails => http://www.rubyonrails.com ]]. His slides are available [[ here => http://www.loudthinking.com/lt-files/worldofresources.pdf ]].
- 5.
- 6. Unfortunately the early version he checked into the [[ rails edge repository => http://dev.rubyonrails.org/browser/trunk/activeresource ]] doesn't quite match his slides.
- 7.
- 8. Below are my (in progress) notes on getting it to work.
- 9.
- 10. h2. Pre-requisites
- 11.
- 12. You need edge rails: @rake rails:freeze:edge@
- 13.
- 14. You need some rest-ful type routes. I've used: @script/plugin install simply_restful@
- 15.
- 16. You need a controller that has the same name as your model (e.g. PeopleController) with index, new, create, show, edit, update and delete methods. Each of these needs to respond sensibly to xml requests, e.g.:
- 17.
- 18. <pre>
- 19. <code>
- 20. def show
- 21. @patch = Patch.find(params[:id])
- 22. respond_to do |format|
- 23. format.html
- 24. format.xml { render :xml => @patch.to_xml }
- 25. end
- 26. end
- 27. </code>
- 28. </pre>
- 29.
- 30. h2. Initialization
- 31.
- 32. The example that DHH gave:
- 33. <pre>
- 34. <code>
- 35. Person = ActiveResource::Struct.new do |person|
- 36. person.uri = "http://api.myremote.com/people"
- 37. person.credentials :name => "me", :password => "password"
- 38. end
- 39. </code>
- 40. </pre>
- 41.
- 42. What works in the code:
- 43. <pre>
- 44. <code>
- 45. Person = ActiveResource::Struct.create
- 46. Person.site = "http://api.myremote.com/people"
- 47. </code>
- 48. </pre>
- 49.
- 50. h2. Get
- 51.
- 52. You can then get the object, as expected:
- 53. <pre>
- 54. <code>
- 55. p = Person.find 1
- 56. </code>
- 57. </pre>
- 58.
- 59. h2. Put / Post / Update
- 60.
- 61. Saving doesn't work, because ActiveResource doesn't set the content-type. Adding this at the start of the request method in [[ActiveResource::Connection => http://dev.rubyonrails.org/browser/trunk/activeresource/lib/active_resource/connection.rb#L60]] seems to help:
- 62. <pre>
- 63. <code>
- 64. arguments << { 'content-type' => 'application/xml' }
- 65. </code>
- 66. </pre>
17:44 Fri 30 Jun 2006
0. h1. Early experiences with Active Resource1.- 0. content moved to [[]]
2. Last updated 22:05 BST Fri 30 June3.4. At the recent RailsConf David Heinemeier Hansson announced his ideas for an active resource library in [[rails => http://www.rubyonrails.com ]]. His slides are available [[ here => http://www.loudthinking.com/lt-files/worldofresources.pdf ]].5.6. Unfortunately the early version he checked into the [[ rails edge repository => http://dev.rubyonrails.org/browser/trunk/activeresource ]] doesn't quite match his slides.7.8. Below are my (in progress) notes on getting it to work.9.10. h2. Pre-requisites11.12. You need edge rails: @rake rails:freeze:edge@13.14. You need some rest-ful type routes. I've used: @script/plugin install simply_restful@15.16. You need a controller that has the same name as your model (e.g. PeopleController) with index, new, create, show, edit, update and delete methods. Each of these needs to respond sensibly to xml requests, e.g.:17.18. <pre>19. <code>20. def show21. @patch = Patch.find(params[:id])22. respond_to do |format|23. format.html24. format.xml { render :xml => @patch.to_xml }25. end26. end27. </code>28. </pre>29.30. h2. Initialization31.32. The example that DHH gave:33. <pre>34. <code>35. Person = ActiveResource::Struct.new do |person|36. person.uri = "http://api.myremote.com/people"37. person.credentials :name => "me", :password => "password"38. end39. </code>40. </pre>41.42. What works in the code:43. <pre>44. <code>45. Person = ActiveResource::Struct.create46. Person.site = "http://api.myremote.com/people"47. </code>48. </pre>49.50. h2. Get51.52. You can then get the object, as expected:53. <pre>54. <code>55. p = Person.find 156. </code>57. </pre>58.59. h2. Put / Post / Update60.61. Saving doesn't work, because ActiveResource doesn't set the content-type. Adding this at the start of the request method in [[ActiveResource::Connection => http://dev.rubyonrails.org/browser/trunk/activeresource/lib/active_resource/connection.rb#L60]] seems to help:62. <pre>63. <code>64. arguments << { 'content-type' => 'application/xml' }65. </code>66. </pre>
17:07 Fri 30 Jun 2006
- 2. Last updated 22:05 BST Fri 30 June
- 3.
- 9.
- 10. h2. Pre-requisites
- 11.
- 12. You need edge rails: @rake rails:freeze:edge@
- 13.
- 14. You need some rest-ful type routes. I've used: @script/plugin install simply_restful@
- 15.
- 16. You need a controller that has the same name as your model (e.g. PeopleController) with index, new, create, show, edit, update and delete methods. Each of these needs to respond sensibly to xml requests, e.g.:
- 17.
- 18. <pre>
- 19. <code>
- 20. def show
- 21. @patch = Patch.find(params[:id])
- 22. respond_to do |format|
- 23. format.html
- 24. format.xml { render :xml => @patch.to_xml }
- 25. end
- 26. end
- 27. </code>
- 28. </pre>
17:02 Fri 30 Jun 2006
39. Saving doesn't work, because ActiveResource doesn't set the content-type. Adding this at the start of the request method in [[ActiveResource::Connection => http://dev.rubyonrails.org/browser/trunk/activeresource/lib/active_resource/connection.rb]] seems to help:- 39. Saving doesn't work, because ActiveResource doesn't set the content-type. Adding this at the start of the request method in [[ActiveResource::Connection => http://dev.rubyonrails.org/browser/trunk/activeresource/lib/active_resource/connection.rb#L60]] seems to help:
17:01 Fri 30 Jun 2006
- 28. h2. Get
- 29.
- 36.
- 37. h2. Put / Post / Update
17:01 Fri 30 Jun 2006
- 0. h1. Early experiences with Active Resource
- 1.
- 2. At the recent RailsConf David Heinemeier Hansson announced his ideas for an active resource library in [[rails => http://www.rubyonrails.com ]]. His slides are available [[ here => http://www.loudthinking.com/lt-files/worldofresources.pdf ]].
- 3.
- 4. Unfortunately the early version he checked into the [[ rails edge repository => http://dev.rubyonrails.org/browser/trunk/activeresource ]] doesn't quite match his slides.
- 5.
- 6. Below are my (in progress) notes on getting it to work.
- 7.
- 8. h2. Initialization
- 9.
- 10. The example that DHH gave:
- 11. <pre>
- 12. <code>
- 13. Person = ActiveResource::Struct.new do |person|
- 14. person.uri = "http://api.myremote.com/people"
- 15. person.credentials :name => "me", :password => "password"
- 16. end
- 17. </code>
- 18. </pre>
- 19.
- 20. What works in the code:
- 21. <pre>
- 22. <code>
- 23. Person = ActiveResource::Struct.create
- 24. Person.site = "http://api.myremote.com/people"
- 25. </code>
- 26. </pre>
- 27.
- 28. You can then get the object, as expected:
- 29. <pre>
- 30. <code>
- 31. p = Person.find 1
- 32. </code>
- 33. </pre>
- 34.
- 35. Saving doesn't work, because ActiveResource doesn't set the content-type. Adding this at the start of the request method in [[ActiveResource::Connection => http://dev.rubyonrails.org/browser/trunk/activeresource/lib/active_resource/connection.rb]] seems to help:
- 36. <pre>
- 37. <code>
- 38. arguments << { 'content-type' => 'application/xml' }
- 39. </code>
- 40. </pre>