I have a rather strange question on C++ to Ruby on Rails communication. I'm trying to update the views in my Rails server whenever certain events happen in my C++ program, both of which are on the same machine. Is it possibl开发者_StackOverflow中文版e to call a method in a controller on a RoR server from a C++ program? And if so, how?
- If these updates are high-frequency, consider bypassing rails and directly updating your database from your C++ app.
- If the updates are infrequent, you might consider using a C HTTP library like curl to fire off updates to the rails app through the HTTP stack; you may want to restrict access to those update controller methods.
- If the updates are very infrequent, it may just be a sufficent solution to shell out to running a rake task from your C++ app.
While it is technically possible to call ruby from C++ via something like SWIG , it does feel like cumbersome solution, which might be difficult to maintain and debug.
You can make the Rails application expose its controller methods through XML-RPC -- there's a library for doing just that. Then just use a C++ XML-RPC library to call into it.
精彩评论