This project is archived and is in readonly mode.

#365 ✓wontfix
Matthew Moore

ActiveResource#attributes= Clobbers All Values

Reported by Matthew Moore | June 9th, 2008 @ 06:37 PM

Although I'm not entirely sure why from looking at the source, but when I call myresource.attributes = { :attribute => 'value' }, all other attributes disappear from myresource, except for :attribute. I'm using Rails 2.1.0.

>> remote = MyResource.find(1)

=> #<MyResource.0x1f6b64c @prefix_options={}, @attributes={"message"=>"Hello world!", "updated_at"=>Sun Jun 01 00:23:24 UTC 2008, "id"=>1, "urn"=>"1-1", "created_at"=>Sun Jun 01 00:23:24 UTC 2008}>

>> remote.attributes = { :message => "NEW MESSAGE" }

=> {:message=>"NEW MESSAGE"}

>> remote

=> #<MyResource:0x1f6b64c @prefix_options={}, @attributes={:message=>"NEW MESSAGE"}>

Comments and changes to this ticket

  • fluxin

    fluxin July 5th, 2008 @ 05:50 AM

    • Tag set to activeresource, bug

    attribute= is meant to assign all attributes not a single one. This is the expected behavior. If you're looking to modify the record use update_attributes.

  • Matthew Moore

    Matthew Moore August 6th, 2008 @ 11:10 PM

    What if you don't want to modify the record remotely, just yet?

    E.g. do the following... This is pretty standard controller code, for an ActiveRecord, i would think.

    remote = MyResource.find(1) remote.attributes = { :message => "NEW MESSAGE" }

    do something else with "remote" before save


    if ... else ... end

  • josh

    josh November 22nd, 2008 @ 07:48 PM

    • State changed from “new” to “wontfix”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>