Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveResource#attributes= Clobbers All Values

#365

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"}>

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

State: wontfix
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. fluxin
    fluxin
    • 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.

    July 5th, 2008 @ 05:50 AM

  2. Matthew Moore
    Matthew Moore

    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

    remote.xyz_method

    if remote.save ... else ... end

    August 6th, 2008 @ 11:10 PM

  3. josh
    josh
    • State changed from new to wontfix

    November 22nd, 2008 @ 07:48 PM