The (natural) combination between ROR and flex
I started thinking how does these 2 technologies combine together, Ruby on rails on the server side and flex on the client side, I found the combination to be very natural and easy, you can actually get quite a bit of satisfaction from combining these 2 together.
I know I did, and in this post I will show you how to build a phone book application where you can create new records in your phone book and have an HTML client side and FLEX client side with only just about 10 minutes of work.
What will we create over here?
Well, like I said, we will be creating a phone book application, we will store data on server side and we will consume this data via a flex application on the client side.
The time-frame for creating this application ia about 10 minutes.
So, let’s begin.
First, I’m going to create a new rails project by using the rails command, the “/projects/rails” is just a folder on my computer while you can actually use whatever folder you prefer for this. Here’s the command:
Now we have a rails template project and we are in the folder. We will create a scaffold for our phone_book table like so:
Notice I did not mess with database configuration or anything, I simply used the rails default configuration for this simple project, if you want to use mySQL or any other server you should edit the database.yml file.
now, we have our database ready and because we created a scaffold we also have pages for creating, deleting, updating and listing the phones in our database. Let’s start our server and go to the page.
This is the command for it and the output from the terminal:
What does that mean?
Does it mean that if I type phones.xml instead of /phones I will get an XML representing my phones list, lets give it a go and see what is happening.
Well, yes it does, we have an XML that represents the list of phones in our database, this is of course dynamic and every phone entry we will created in our database will be added to that XML.
Believe it or not we are done with server side, we have created a phone book (basic) application where we can add, delete, update and list our phones, we created an XML file that can be consumed by a number of other applications.
Now, let’s create a client side for out application. I’ll be using flex builder 3 to create a flex client side.
We will start by creating a new project, just the old regular file–>new–>Project, select a location for you project and open up the main.mxml file of your application.
First, let’s see what we need.
- HTTP service for getting the data out of the server
- An XML object to cache the data inside the application
- Datagrid to show this data
Let’s create a listner for the creationComplete Event, create the HTTP service and attach needed event to it, when the service return result let’s fill our XML from that result.
Your code now looks like this
As you can see our entire application is less then 50 lines of code.
We get sorting, column ordering out of the box when using flex
This is what our application looks like:
That’s it, our application is ready and working, you can go ahead and add some more phones, delete and see how it affects your flex client side.
The options are huge when combining these 2 powerfull technologies together, I love working with these and you will as well, I promise you.
Feel free to comment and let me know what you think, hope you enjoyed.Submit to Hacker News
[NOTE] This post has been imported to Hugo from a Wordpress blog. It may be broken, missing images, code snippets or other information.
[NOTE] updated November 6, 2009. It's 3369 days old . This article may have outdated content.