Let's say I have 2 rails app, a "server" and a "client" for a REST
resource.

When you create a new ActiveRecord, you have all attributes whit its
defaults values on place:

>> Article.new  # On "server" application
=> #<Article id: nil, name: nil, description: nil, price: nil,
created_at: nil, updated_at: nil>

Let's compare that with what happens when we create an ActiveResource
on client:
>> Article.new
=> #<Article:0xb7735124 @prefix_options={}, @attributes={}>

Where do the "id", "name", "description", "price", etc... attributes
went? When creating a record, it does not initialize the attributes.

       In my opinion, the best way to fix this would be to request a
new record to the "server"
application via a HTTP request. That way the attributes names of the
resource would return it's
default values. In my "server" app, requesting 
http://localhost:3000/articles/new.xml
responds the right thing:

<article>
       <created-at type="datetime" nil="true"/>
       <description nil="true"/>
       <name nil="true"/>
       <price type="decimal" nil="true"/>
       <updated-at type="datetime" nil="true"/>
</article>

       There's a caveat for this: making a request in every "new" is
expensive for both server and client. In the end, I think this is the
right solution anyway.

Someone made a PATCH to "fix" the problem (http://dev.rubyonrails.org/
ticket/9862), although the proposed solution is not the ideal IMHO.

What's your opinion?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to