Reputation: 31
I want to make my web service by using RoR and extend this service to mobile.
I searched how to connect RoR with android on google, However , The answer is building new ROR application with API only mode.
But I want to add API to the existing web application. How can i do this?
thank you!
Upvotes: 1
Views: 1088
Reputation: 312
The simple workaround is to create a api folder(api/v1 incase you are also planning versioning in future) in controllers,views & helpers.
Create a controller in controllers folder & the content would be like:
class Api::V1::TestsController < ApplicationController
def show
render 'show.json.jbuilder'
end
end
User Jbuilder to return response in json format. There would be a json view api/tests/show.json.jbuilder.
The content of that file would be like:
json.equipment do
json.id @contact.id
json.name @contact.name
json.type @contact.type
end
and you are good to go.
Upvotes: 2