ActiveResource and RESful edit

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: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 <team></team> tags aren't there.

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.

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

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.

Darn, that should read

render :xml => @team.to_xml

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

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.

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