From Flex, to Spry, to Rails 4
For one of the product we are currently developing for ourselves, we want to create a very slick interface. When we started, I was doing some Flex work at that time, so we (I) decided to start building the UI in Flex against a RESTFul Rails application. I used Cairngorm and I spent 10 days over several month developing the main functionality. I created a Flex ActiveResourceClient class (Actionscript) to access our RESTFul Rails server. I found a nice mechanism to display Rails errors in Flex similar to what scaffolding provides. I managed to add some Flex charting to show time series. We also nicely integrated testing with rake to allow running Flex unit tests from rake (rake test:flex). All was good. All was good, if it wasn’t for a little feeling that coding was slowing down. And it was getting a little slow to add new features. And I wasn’t so sure any more that we really needed flex for that project. So as the server was RESTFul, I thought why not use Adobe’s SPRY framework that consumes XML to drive HTML generation in Javascript. And our Rails application returns XML. So I devised a nice way to integrate Spry with Rails. I thought let’s give it a try. Four hours later I had a working demo, and 12 hours later a working application. The result was a cool application that behaves like Gmail. Erb was used to generate Spry templates and once the client was loaded (html+javascript) only calls to get new data from the server where issued. Then came RailsConf 2007 and my vacations (without any computer). Well, coming back to the project I wondered if I really needed Spry and if I could just go plain old Rails for the views. So on I went back and rewrite once more the UI just using standard Rails views. Eight hours later I had a clean, simple UI.
Lessons learned: keep it simple, don’t use technology for technology, don’t find a problem to your solution. Well, I got to enthusiastic about trying out new stuff, but now we are back on track.
So, 10 days for Flex, 12 hours for Rails+Spry, and 8 hours for plain Rails. Now this comparison is not fair as we spent quite some time on integrating Flex and Rails. But definitively when a Flex application becomes quite large, the compile time causes a drag to the development time. This is compared to plain Rails where you can just keep doing changes at which ever level you want (model, controller, view) and instantly see the change, resulting in a way faster development cycle. Don’t take me wrong I love Flex, but for this project Rails is a better fit.

Hey Daniel,
Adobe recently put the Flex 3 Beta out on Labs, and it includes numerous compiler tweaks to solve your lag times.
FYI, Kevin
Hi Kevin,
Thanks for the feedback. I am using Flex 3, but not on this project and it looks really promising. I love the AIR integration. I am not sure how to best describe the difference in development speed I was mentioning. It’s not so much the compile time rather than how long it takes to access the part of the application you want to change. With Flex you may need to perform several steps to go down to where you want in your application, while in html you can just push ‘Refresh’. That difference became apparent when I went straight back to Rails and I felt like kicking but! This could have been be solved maybe by modularizing the application in way smaller parts and have each part be developped separatly or buy using some kind of deep linking. Also I believe there a many cases where Flex is faster to build an UI than with Rails and situations where Flex is easier than using some complex javascript/Ajax approach. But I don’t need to tell that to you.
Daniel,
I have been experimenting with glue code between Flex and Rails as well using POX (plain old xml). I found that putting RESTfull control in the client is just like extending Rails into Flex. In the end all models were defined in AS3 too and every interaction had to be modelled op top of CRUD-like operations. Now, I am working on the concept of Commands and Selections instead to better decouple the Flex presentation layer from the Rails services layer. Recently, I put the code of this experiment on Google Code: http://code.google.com/p/pocogese/ I am interested in your experience using Cairngorm with respect to this.
It is true that using technology just for technology sake should be avoided. I also think that during the 10 days of building you discovered the essence of what you wanted to build, rebuilding in spry allowed you to focus on the essentials. Rinse and repeat for plain old html with scriptaculous…
hypothetically, what if you rebuilt what you have in html now in flex, how much time would that cost you?
Furthermore, i agree 100% that coding in rails feels much more liberating than coding in flex. Hacking Flex is rather cumbersome compared to hacking rails.
my two cents.