Attached is a patch that changes how unsaved ActiveResource objects handle method missing for their attributes.
Currently, new ActiveResource objects have no attributes in their attributes hash until a save has been attempted and the remote resource's attributes are copied into the ActiveResource object.
This makes it hard to drop ActiveResource objects into forms and other locations that expect there to be attributes on new objects (even if there is no value for each attribute).
The patch alters how ActiveResource checks the attribute's hash. For new (unsaved) ActiveResource objects nil will always be returned if an unknown method is called that does not end in '=' or '?' (those cases are handled differently by ActiveResource.
Saved ActiveResource objects continue to behave as expected.
person = Person.new # Person is an ActiveResource subclass
person.unknown_method
#=> nil
person.save
# 200. Saved
person.unknown_method
# NoMethodError
One major reason for this patch is to allow ActiveResource use with standard form builders. The view code below currently returns a NoMethodError on new person objects because person has no attributes until the Resource has been created and xml returned. The patch allows ActiveResource objects to behave more like ActiveRecord objects when used in forms.
<% form_for :person, :url => people_url do |f| %>
<p><label>name:</label><br/><%= f.text_field 'name' %></p>
<p><label>age:</label><br/><%= f.text_field 'age' %></p>
<p>
<%= f.submit "Create" %>
</p>
<% end %>