views:

166

answers:

3

I'm working on a project that has a website in Rails and a C# GUI that use the same database and data models. I'd like to share the (active)models between the two parts. Any ideas on how this is possible?

A: 

First thing that comes to mind for me would be to expose RESTful web services from the Rails application, and consume those services in your C# client application. I don't know of a way to avoid duplication if you want POCO's in your C# application - maybe write a CodeSmith or T4 template that reads schema.rb and generates POCO's.

Andy Gaskell
You can use the xsd.exe tool to generate the c# classes from the schema of the webservice.
MattMcKnight
I'm not sure that would work with a RESTful web service. My understanding is that you can generate proxy classes if you're using SOAP based services.
Andy Gaskell
+1  A: 

IronRuby is exactly for that.

You will need to run Ruby on Rails with IronRuby (you can do that via IIS too) and then you can call your C# assemblies like they were Ruby libraries.

Some resources to get you started:

  • http://IronRuby.net - official site with some documentation (not full but you will find some good info there)
  • http://www.IronShay.com - my blog with several posts about IronRuby. You can also contact me via its contact form if you need more directions
  • http://www.ruby-forum.com/forum/34 - The IronRuby forum/mailing list, questions answered by members of the IronRuby community and the team members as well.
Shay Friedman
IronRuby looks promising. However, I'm having trouble with ActiveRecord/MySql. Is that supposed work out of the box? Installing the mysql gem with igem install mysql doesn't solve the issue.
phillee
+1  A: 

The short answer is you can't without redefining them on the C# gui. You can expose the controllers as WSDL/SOAP instead of the restful stuff, then you can have visual studio generate the proxies for you. C# is really bad at dynamic stuff so you can't just take the ruby models and reuse them in C# because they need to be compiled.

You can of course write your own proxy generation tool for the "restful" resources of rails but at the end of the day you'll have to duplicate the model code somehow.

Like shay says you can use IronRuby to bridge the gap but it depends do you want to reuse the ActiveRecord classes or are you using the website as your point to get to the data? When you want to reuse the activerecord models then IronRuby is the way to go to talk to your database (but to get good integration with C# you would have to create strong typed wrappers around the models, so I don't really see the point).

Casual Jim