The best way to handle this is to provide an API from the web application that external applications can interface with. One great thing about Rails is it basically supports this out of the box.
Take a typical controller action for viewing a student from the web.
class StudentsController < ApplicationController
def show
@student = Student.find(params[:id])
end
end
When the request is made to /students/1 then the students/show template will be rendered for Student with ID#1.
Rails has the ability to append xml/json to the end of the URL in order to request processing with a different format type.
class StudentsController < ApplicationController
respond_to :html, :json
def show
@student = Student.find(params[:id])
respond_with(@student)
end
end
This sets up a feature of ActionController called the Responder. Now when a request is made to /students/1.json the controller will call as_json on the Student model, which by default takes all of the models attributes and converts it to a json object. This can be customized by overriding as_json in your Student model.
For making updates you can follow a similar pattern. You submit to the server using a PUT request to /students/1.json. The request is not in JSON, the library you use likely has support for setting the vars, make sure it is in the format that Rails expects (ie student[field]). The Rails middleware will take care of the rest.
class StudentsController < ApplicationController
respond_to :html, :json
def update
@student = Student.find(params[:id])
@student.update_attributes(params[:student])
respond_with(@student)
end
end
Note that with Responders there is no checking if update_attributes worked, the respond_with will do that for you. If there are errors you will get a HTTP 422 Unprocessable Entity as a response code, and the body of the response will be a JSON object with the errors.
It's also worth mentioning that you can substitute json with xml in all of these examples if you prefer XML response bodies instead of JSON.