Hi, I''m being asked to use this api to retrieve the data because the ror application won''t have any database to store the users information, the database will only be accessed by this api. For example for creating a new user I have to send a post request with a json format to the url: api.server.com/api/v/user/subs So in my model I have this: class User << ActiveResource::Base self.site = "http://api.server.com/api/v" self.format = :json end and when I try this: u = User.new u.save I got 400 Bad request because the request is send to this location POST http://api.server.com:80/api/v/users.json I guess the first problem is the rails conventions for pluralize collections, so it write users instead of user like is needed in the url, the second problem is that after user I need to and, in this action of create a new user, the /subs and I don''t know how to do this. After that problem I have another issue in the body of the request it sends the json like this {"user":{"email":"mail"}} but the api is expectin something like this {"email":"mail"} After saying all this I want to know if it is a proper way to make AResource to behave the way I need or if already exist a plugin/gem to work with this kind of APIs or if a need to come with a new solution and leave behind AR -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
So far I came with a solution for two of this issues: 1) Url using a pluralized name of the object User solved with: >>self.collection_name = "user" 2) Removing the extension from the URL, I solve this adding a Module that I found googling around to override some methods of AR. I thought that I had found the solution for another problem, removing the element_name from the json adding: >>ActiveResource::Base.include_root_in_json = nil But my json still have this node {"user":{"email":"hi''\n"}} -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Maybe you can use the Custom Methods (http://api.rubyonrails.org/classes/ActiveResource/CustomMethods.html) to try if it works. And the try to use the "normal" ActiveResource ... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/_EEA4JhgBvUJ. For more options, visit https://groups.google.com/groups/opt_out.
There is the remove_root method, is this what you want? https://github.com/rails/rails/blob/6b4bbb427455ec1af6bdf0896a62129bd3c8c4aa/activeresource/lib/active_resource/formats.rb#L14 2012/10/11 arturo drlt <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> So far I came with a solution for two of this issues: > > > 1) Url using a pluralized name of the object User solved with: > > >>self.collection_name = "user" > > 2) Removing the extension from the URL, I solve this adding a Module > that I found googling around to override some methods of AR. > > I thought that I had found the solution for another problem, removing > the element_name from the json adding: > > > >>ActiveResource::Base.include_root_in_json = nil > > But my json still have this node > > {"user":{"email":"hi''\n"}} > > -- > Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- Fernando Almeida www.fernandoalmeida.net -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Or do you want the ActiveResource::Base.include_root_in_json = false ? https://github.com/rails/activeresource/blob/master/test/cases/base_test.rb#L1092 2012/10/13 Fernando Almeida <fernando-7WGqr3rU1tV1NwFxuVVnt9HuzzzSOjJt@public.gmane.org>> There is the remove_root method, is this what you want? > > > https://github.com/rails/rails/blob/6b4bbb427455ec1af6bdf0896a62129bd3c8c4aa/activeresource/lib/active_resource/formats.rb#L14 > > > > 2012/10/11 arturo drlt <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > >> So far I came with a solution for two of this issues: >> >> >> 1) Url using a pluralized name of the object User solved with: >> >> >>self.collection_name = "user" >> >> 2) Removing the extension from the URL, I solve this adding a Module >> that I found googling around to override some methods of AR. >> >> I thought that I had found the solution for another problem, removing >> the element_name from the json adding: >> >> >> >>ActiveResource::Base.include_root_in_json = nil >> >> But my json still have this node >> >> {"user":{"email":"hi''\n"}} >> >> -- >> Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> > > > -- > Fernando Almeida > www.fernandoalmeida.net > >-- Fernando Almeida www.fernandoalmeida.net -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Xavael wrote in post #1079637:> Maybe you can use the Custom Methods > (http://api.rubyonrails.org/classes/ActiveResource/CustomMethods.html) > to > try if it works. > > And the try to use the "normal" ActiveResource ...Thx for that module it will be very helpful Fernando Almeida wrote in post #1079656:> There is the remove_root method, is this what you want? > >https://github.com/rails/rails/blob/6b4bbb427455ec1af6bdf0896a62129bd3c8c4aa/activeresource/lib/active_resource/formats.rb#L14> > > 2012/10/11 arturo drlt <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> > >> I thought that I had found the solution for another problem, removing >> Posted via http://www.ruby-forum.com/. >> > -- > Fernando Almeida > www.fernandoalmeida.netYeah I want something like that, with this I think I have all my issues solved for now thx guys. -- Posted via http://www.ruby-forum.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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.