Microsoft Gunning For Ruby on Rails
Microsoft has declared victory over J2EE, and is now setting their sites on Ruby on Rails.
I think I’ve got a case of Deja Vu.
Microsoft has declared victory over J2EE, and is now setting their sites on Ruby on Rails.
I think I’ve got a case of Deja Vu.
Salesforce, the large Customer Relationship Management tool, and Ruby on Rails, the elegant web development framework, seem like an awkward pair. About as awkward as dipping a Wendy’s french fry in a frosty.
Salesforce is large, often times confusing, and is a tool built for handling lots of different jobs. Rails is lean, elegant, and designed specifically for making web development easier. While Salesforce and Rails are dramatically different, they actually work very well together (much like a Wendy’s french fry dipped in a frosty – trust me).
This unlikely pairing is sparked by ActiveSalesforce, a Ruby on Rails connection adapter to Salesforce-managed data. This Ruby Gem makes working with Salesforce data about as easy as the Rails-MySQL combination.
Highgroove Studios is working on a Salesforce-Rails application, and one of the things we have to do is synchronize a local MySQL database with Salesforce. This is needed because the connection to Salesforce is slower than when working with a local database, and several parts of the application are time-sensitive.
Here’s a look at how we designed the application to synchronize data between the local database and Salesforce.
About half of the geeks of the world prefer newsgroups for communication and the other half swears by mailing lists. (A tiny percentage prefer web forum or pigeon, but clearly these people suffer from insanity.) The Ruby community has long had both: the comp.lang.ruby newsgroup and the Ruby-Talk mailing list.
In 2001, a band of clever adventurers and Rubyists united the two communities with heroic feats of hacking. A “gateway” script was installed that dutifully ferried all messages from one group to the other and visa versa. This was a blessing, because both sides now shared the collective Ruby knowledge. A golden age began.
Unfortunately, a few months back, the evil server hosting monster struck and slew the gateway with a single stoke! (In all fairness, the hosting provided to the gateway over the last five years was more than generous, but that just doesn’t make for as good a story and I’m telling this one!) The golden age ended, the community shattered into two halves…
At HighGroove, we couldn’t stand for that.
Knowing the peril involved, I enlisted the help of the brave HighGroove SysWizard Charles and we went in search of a gateway in need of rescue. It was a long journey and we suffered a minor defeat along the way, but good always triumphs over evil and we cannot be stopped easily!
I’m happy to bring the good news to all the peoples of the Ruby kingdom: the gateway has been resurrected. The golden age has come again.
Please join me thanking all those patrons who sponsored our quest:
Thanks to these brave men, the knowledge is again shared by all! Use it wisely my fellow adventurers…
Realizing that hitting “talk” on my phone dialed the previous number. Figuring out that the arrow next to my fuel gauge showed which side the car fuel door is on. Tab completion.
A couple of times a month, I’ll have a “wow – that’s so useful and so simple” moment. One of the first times I experienced that with Ruby was with #method_missing.
Metaprogramming is your secret identical twin that likes doing all of the things you don’t. Need to take out the trash? Just tell your twin. Need to program in Java? Send your twin an email.
Metaprogramming, defined as writing code that writes code by Why The Lucky Stiff, makes scaffolding, associations, validations, and the many magical parts of Rails possible. Implementing metaprogramming techniques can drastically eliminate duplicate code, making your applications far easier to maintain and build. It also lets your code do the work – not you.
CampusSync.com, a client project of ours, is a collaboration site for college students. It has several administration areas that are almost identical, but not a good fit for Rail’s standard scaffolding. The solution to eliminating duplicate code: roll our own metaprogramming solution.
UPDATE: rails_cron is no longer available, and daemon_generator has moved. BackgrounDRB has gone through a major rewrite, and I’ve got a chapter on Background Processing in The Rails Way by Obie Fernandez. Thanks to Chris Johnson and Douglas F Shearer for the updated information.
Without a way to run long-running tasks, Heartbeat, our 2006 Rails Day Entry, wouldn’t have had a pulse.
Like Heartbeat, most web applications need to run regulary scheduled or long-running tasks at some point in their life-cycle. These tasks are often not inititated by a web request. How can you check the validity of a URL every 15 minutes? How do we get an eCommerce store to calculate the most popular items every 5 hours? How can we re-index our site for searching every day?
If you’ve ever had to do this, chances are you’ve used cron (the *nix tool used to schedule remote tasks) coupled with script/runner. However, wouldn’t it be great if you could maintain your tasks and background “jobs” inside the ruby language, or even better, as part of your Rails application?
Let’s explore two ways to do this: the excellent BackgrounDRb plugin by Ezra Zygmuntowicz, which was used to power Heartbeat, and the fabulous rails_cron by Kyle Maxwell.
The demo is up – take Heartbeat for a spin.
It’s a single-web page control panel that lets you run any rake task within your application’s directory, from deployment to tests to migrations. If you can write a rake task, Heartbeat can execute it! Additionally, you can use it to monitor the uptime of your URLs.
The app makes extensive use of RJS templates and AJAX.
Heartbeat was built by myself (Derek Haynes) and Charles Brian Quinn of Highgroove Studios during the 24-Hour coding marathon that was Rails Day 2006.
We’ve got big plans for Heartbeat, especially as it relates to Slingshot, our Rails Business Hosting Service. Stay tuned.
Not only were we a Rails Day 2006 Sponsor, but we also competed.
Our entry is called Heartbeat. It’s a simple, elegant, web-based tool for monitoring and maintaining Rails-based applications. From the Heartbeat home page:
Monitor the uptime of URLs and run your application’s rake tasks. Manage your Rails applications from a web interface! Heartbeat can be extended however you want – if you can write a rake task, Heartbeat can execute it!
Here are some screenshots from the application we completed in 24 hours:
We’re not done with Heartbeat just yet. This is only the first 24 hours of development.
Auto-Complete is a great tool when it provides possible results BEFORE you finish typing. Unfortunately, using Rails’s included AJAX helpers to query the database as you type often results in a large delay before matches are returned.
However, there is a lightning-quick option: pre-fetch the results in a Javascript array.
In a client project, users can add labels to events on their calendar. To prevent users from creating variations of the same label name (i.e. – “favorite” vs. “favorites”), we needed to provide faster auto-complete functionality than that available through Rails’s provided AJAX helpers.
We created a simple helper method for this case (special thanks to Chad Fowler and his Rails Recipes book for the inspiration).
Take a look at the local_auto_complete_field helper method. TXT
<%= local_auto_complete_field('name',@labels) %>
In the above example, we are adding JavaScript-powered auto-complete functionality to the 'name' text field. The JavaScript array is generated by calling #name on each element in the @labels array. To override this behavior:
<%= local_auto_complete_field('name',@labels,
:method => 'description') %>
Here’s to faster auto-completion!
Another San Francisco Ruby Meetup. Another record-breaking attendance mark (has any Ruby group in the world brought together more than 110 people?).
Here’s the slides from my presentation on how Highgroove Studios molds its team and development process to utilize Ruby on Rails: