Wrong URL when consuming existing Java REST API using rails ActiveResource
I am new to ruby on rails.I am trying to consume my existing Java REST api using Rails, ActiveResource class, but every time resource URL hit, is wrong (https://myapp/resource/**apis**/responce.json
), where the correct url is (https://myapp/resource/**api**/responce.json
)
Problem is active resource mapping apis/ instead of api/
Below is my code for model => app/model/api.rb
class Api < ActiveResource::Base
self.site = "https://myapp/resource"
self.format = :json
self.element_name = "api"
end
Code in app/controllers/api_controller.rb
@api = Api.get(:responce, :key => "key", :userId =>'1')
T开发者_Go百科he above code always give 404 error, when I check the logs, resource is hitting https://myapp/resource/**apis**/responce.json?key=key&userId=1
Where it must hit resource URL as https://myapp/resource/**api**/responce.json
The self.element_name = "api"
is fixing the pluralization when you are doing a find(:first) or similar. What you need is self.collection_name = "api"
. That should fix the URL it is creating.
精彩评论