# ActiveResource and RESful edit

**URL:** <https://www.ruby-forum.com/t/activeresource-and-resful-edit/104142>\
**Category:** Rails\
**Created:** [May 14, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/activeresource-and-resful-edit/104142 "2007-05-14T18:10:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 14, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/activeresource-and-resful-edit/104142/1 "2007-05-14T18:10:25Z")

</div>

Hi  
I’d like to know how to have ActiveResource generate a URL for the

/teams/1/edit

type of resource.

I’ve got custom\_methods.rb and have used

Team.find(1).get(:edit)

This generates

[http://localhost](http://localhost):xxxx/teams/1/edit.xml

But all I get returned is a hash of the attributes (in this case of  
team 1), rather than an object of team 1.

In other words the tags aren’t there.

Is this right?

Jason

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 14, 2007, 6:17pm UTC](https://www.ruby-forum.com/t/activeresource-and-resful-edit/104142/2 "2007-05-14T18:17:25Z")

</div>

On 5/14/07, jason [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Team.find(1).get(:edit)  
> Is this right?
> 
> Jason

That depends entirely on your edit action in your controller. Keep in  
mind, ActiveResource won’t give you raw XML back, it will return  
resource objects.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 14, 2007, 6:36pm UTC](https://www.ruby-forum.com/t/activeresource-and-resful-edit/104142/3 "2007-05-14T18:36:31Z")

</div>

OK, the controller on the resource is simply:

def edit  
@team = Team.find(params[:id])  
render :xml =\> @venture.to\_xml  
end

Which creates the xml, but all I have back in the client is a hash,

{“foo”=\>bar}

not the resource object I expected, like,

Team:object\_id @prefix\_options=(), @attributes={“foo”=\>“bar”}

?

J

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 14, 2007, 8:04pm UTC](https://www.ruby-forum.com/t/activeresource-and-resful-edit/104142/4 "2007-05-14T20:04:43Z")

</div>

On 5/14/07, jason [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> {“foo”=\>bar}
> 
> not the resource object I expected, like,
> 
> Team:object\_id @prefix\_options=(), @attributes={“foo”=\>“bar”}

You’re returning a venture. Do you have a resource for it? I’m not  
even sure what the custom actions are supposed to return. I’d go by  
the source or the unit tests to see if you’re getting the expected  
result.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 14, 2007, 10:45pm UTC](https://www.ruby-forum.com/t/activeresource-and-resful-edit/104142/5 "2007-05-14T22:45:11Z")

</div>

Hi  
I’ve just read ActiveResource custom\_method.rb more closely. Re:

# Person.get(:active) #=\> [{:id =\> 1, :name =\> ‘Ryan’}, {:id =\>

2, :name =\> ‘Joe’}]

Looks like I’m getting exactly what I should expect to get.

This isn’t really very helpful. All I want to do is understand all  
the relevant ways to interact with the standard ActiveRecord RESTful  
API. Once I’ve got it figured I’ll post, promise.

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 14, 2007, 9:14pm UTC](https://www.ruby-forum.com/t/activeresource-and-resful-edit/104142/6 "2007-05-14T21:14:51Z")

</div>

Darn, that should read

render :xml =\> @team.to\_xml

Really this is scaffold code. As basic as it can get.

---

<div class="post-metadata">

**Author:** ![jason](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@jason](https://www.ruby-forum.com/u/jason)\
**Post date:** [May 15, 2007, 9:01am UTC](https://www.ruby-forum.com/t/activeresource-and-resful-edit/104142/7 "2007-05-15T09:01:09Z")

</div>

On 5/14/07, jason [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> the relevant ways to interact with the standard ActiveRecord RESTful  
> API. Once I’ve got it figured I’ll post, promise.

IIRC, #get/post/put/delete are lower level than what you’re wanting.  
Try #find

Person.find(:all, :from =\> :active)  
Person.find(:one, :from =\> ‘/companies/5/manager.xml’)

Also, #edit will usually be a browser-only action for displaying a  
form. There’s no “XML forms”, so the data from #show should be  
sufficient.

@person = Person.find(1)  
@person.age = 21  
@person.save

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
