# Updates to an ActiveResource model

**URL:** <https://www.ruby-forum.com/t/updates-to-an-activeresource-model/145025>\
**Category:** Rails\
**Created:** [August 5, 2008, 11:46am UTC](https://www.ruby-forum.com/t/updates-to-an-activeresource-model/145025 "2008-08-05T11:46:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/4491bb/32.png) [@stevel](https://www.ruby-forum.com/u/stevel)\
**Post date:** [August 5, 2008, 11:46am UTC](https://www.ruby-forum.com/t/updates-to-an-activeresource-model/145025/1 "2008-08-05T11:46:20Z")

</div>

I have a front end Rails 2.1 app which makes ActiveResource model  
calls to an ActiveRecord back end.  
When I edit a record, and save - the backend is calling create rather  
than update. Any thoughts on where I should investigate the cause?

== front end ==  
[Query model]

class Query \< ActiveResource::Base  
self.site = ENV[“AR\_SITE”]

def update\_attributes(attributes)  
self.attributes = attributes  
save  
end

end

[Query controller]

# PUT /queries/1

# PUT /queries/1.xml

def update  
@query = Query.find(params[:id])  
logger.info @query.new?.to\_s  
respond\_to do |format|  
if @query.update\_attributes(params[:query])  
flash[:notice] = ‘Query was successfully updated.’  
format.html { redirect\_to(@query) }  
format.xml { head :ok }  
else  
format.html { render :action =\> “edit” }  
format.xml { render :xml =\> @query.errors, :status  
=\> :unprocessable\_entity }  
end  
end  
end

[log]  
Rendering queries/edit  
Completed in 0.20789 (4 reqs/sec) | Rendering: 0.00468 (2%) | DB:  
0.00000 (0%) | 200 OK [[http://localhost/queries/25/edit](http://localhost/queries/25/edit)]

Processing QueriesController#update (for 127.0.0.1 at 2008-08-05  
10:29:03) [PUT]  
Session ID:  
BAh7BzoMY3NyZl9pZCIlNzI2YjkxOWFiM2VhM2U4NDU4NTIzZDdlNmUyZTFm  
ZGMiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhh  
c2h7AAY6CkB1c2VkewA=–61d650921b3c0ce3c4165301c271771ef873f8eb  
Parameters: {“commit”=\>“Update”,  
“authenticity\_token”=\>“e1303142494a26327be638a323ce4b1c7a13a78b”,  
“\_method”=\>“put”, “action”=\>“update”, “id”=\>“25”,  
“controller”=\>“queries”, “query”=\>{“query\_type\_id”=\>“1”,  
“query\_string\_id”=\>“1”, “comment”=\>“updated at 10:28”,  
“query\_status\_id”=\>“1”}}  
false {ie query id 25 exists already}  
Redirected to [http://localhost:3000/queries/26](http://localhost:3000/queries/26)  
Completed in 0.25446 (3 reqs/sec) | DB: 0.00000 (0%) | 302 Found  
[[http://localhost/queries/25](http://localhost/queries/25)]

== back end ==  
Processing QueriesController#show (for 127.0.0.1 at 2008-08-05  
10:29:03) [GET]  
Session ID: 72d6d6a58c3fb2234fc134e6f4efc25c  
Parameters: {“format”=\>“xml”, “action”=\>“show”, “id”=\>“25”,  
“controller”=\>“queries”}  
Query Load (0.000559) SELECT \* FROM “queries” WHERE  
(“queries”.“id” = 25)  
Completed in 0.01947 (51 reqs/sec) | Rendering: 0.00015 (0%) | DB:  
0.00056 (2%) | 200 OK [[http://localhost/queries/25.xml](http://localhost/queries/25.xml)]

Processing QueriesController#create (for 127.0.0.1 at 2008-08-05  
10:29:04) [POST]  
Session ID: 25abed8e86dd5cbc7810ed9cc3b3d33a  
Parameters: {“format”=\>“xml”, “action”=\>“create”,  
“controller”=\>“queries”, “query”=\>{“query\_type\_id”=\>“1”,  
“query\_string\_id”=\>“1”, “comment”=\>“updated at 10:28”,  
“query\_status\_id”=\>“1”}}  
Query Create (0.000358) INSERT INTO “queries” (“updated\_at”,  
“query\_type\_id”, “query\_string\_id”, “comment”, “query\_status\_id”,  
“created\_at”) VALUES(‘2008-08-05 09:29:04’, 1, 1, ‘updated at 10:28’,  
1, ‘2008-08-05 09:29:04’)  
Completed in 0.02947 (33 reqs/sec) | Rendering: 0.00243 (8%) | DB:  
0.00036 (1%) | 201 Created [[http://localhost/queries.xml](http://localhost/queries.xml)]
