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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5/14/07, jason <jason-DBciWbShXhpAfugRpC6u6w@public.gmane.org> wrote:> > 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? > > JasonThat 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 Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On 14 May, 17:15, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5/14/07, jason <j...-DBciWbShXhpAfugRpC6u6w@public.gmane.org> wrote: > > > > > > > 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. > > -- > Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5/14/07, jason <jason-DBciWbShXhpAfugRpC6u6w@public.gmane.org> wrote:> > 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"}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 Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Darn, that should read render :xml => @team.to_xml Really this is scaffold code. As basic as it can get. On 14 May, 19:03, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 5/14/07, jason <j...-DBciWbShXhpAfugRpC6u6w@public.gmane.org> wrote: > > > > > 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"} > > 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 Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On 14 May, 20:13, jason <j...-DBciWbShXhpAfugRpC6u6w@public.gmane.org> wrote:> Darn, that should read > > render :xml => @team.to_xml > > Really this is scaffold code. As basic as it can get. > > On 14 May, 19:03, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 5/14/07, jason <j...-DBciWbShXhpAfugRpC6u6w@public.gmane.org> wrote: > > > > 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"} > > > 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 Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephist...--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5/14/07, jason <jason-DBciWbShXhpAfugRpC6u6w@public.gmane.org> wrote:> > 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 -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---