When I do a mapping in active resource, its default request to the Ruby on Rails always automatically add the extension at the end of the url. For example: I want to get user resource from Ruby on Rails by mapping as below:
class user < ActiveResource::Base self.site = 'http://localhost:3000' end
And something that I need, I just want it pass the url without extension like
http://localhost:3000/userIn contrast it automatically adds the extension at the end of the url like
http://localhost:3000/user.xml
How can I omit the extension of the url when I make request from the active resource mapping?
At first, I did use @Joel AZEMAR's answer and it worked quite well until I started using PUT. Doing a PUT added in the .json/.xml.
A bit of research here, revealed that using the ActiveResource::Base#include_format_in_path
option worked far better for me.
Without include_format_in_path:
class Foo < ActiveResource::Base
self.site = 'http://localhost:3000'
end
Foo.element_path(1)
=> "/foo/1.json"
With include_format_in_path:
class Foo < ActiveResource::Base
self.include_format_in_path = false
self.site = 'http://localhost:3000'
end
Foo.element_path(1)
=> "/foo/1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With