jason
May 14, 2007, 6:10pm
#1
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 tags aren’t there.
Is this right?
Jason
jason
May 14, 2007, 6:17pm
#2
On 5/14/07, jason [email protected] 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://weblog.techno-weenie.net
http://mephistoblog.com
jason
May 14, 2007, 6:36pm
#3
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
jason
May 14, 2007, 8:04pm
#4
On 5/14/07, jason [email protected] 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://weblog.techno-weenie.net
http://mephistoblog.com
jason
May 14, 2007, 10:45pm
#5
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.
jason
May 14, 2007, 9:14pm
#6
Darn, that should read
render :xml => @team.to_xml
Really this is scaffold code. As basic as it can get.
jason
May 15, 2007, 9:01am
#7
On 5/14/07, jason [email protected] 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://weblog.techno-weenie.net
http://mephistoblog.com