This is going to be a simple tutorial to show you how easy it is to use Flex to read in XML from a Ruby on Rails application.
Ensure you are up and running with Ruby, Rails and Flex at this point. There are plenty of instructions on the web if you unsure how to set this all up.
The first thing we are going to do is create the Rails project. From my command prompt I create a folder called “Rails_Projects”. Navigate to that folder (or whatever your gonna call it). At command prompt enter the following:
This command will then execute and you will see a bunch of data dumped to the screen as Rails generates the project. Once the project has been generated go ahead and move into the “SendXML” folder from the command prompt.
We now need to generate the databases using the following command (again, make sure you are in the “SendXML” folder):
Now we have the databases created but no schema for the database. Lets add a very simple schema now:
This is a pretty simple schema as we only have one column. You could of course make this much more complex pretty easily but for now we will stick with simple. Now we will actually have Rails create that schema by doing the following Rake task:
Now we need to actually add some data. Lets run the Rails project in order to do that. Again, from the command prompt:
Go to a browser and navigate to: http://localhost:3000/quotes
Now enter in a new quote.
While your at it, enter this into your browser to see the results in XML: http://localhost:3000/quotes.xml
That takes care of the Rails part of this. Go ahead now an fire up Flex Builder 3 and create a new project. I called mine “TalkToRails”.
Here is the MXML:
You can see this is just a simple HTTP Service that calls the Rails application and requests the XML. Obviously if you returned more than one record you would need to modify this code. Also you could also do this same thing via data binding with much less code than I showed here.