What Every Webmaster and Web Developer MUST Know About Ruby on Rails and AJAX

来源:百度文库 编辑:神马文学网 时间:2024/03/28 20:31:16
What Every Webmaster and Web Developer MUST Know About Ruby on Rails and AJAX
Posted by Matt Lightner underWeb Hosting ,Development ,Business Strategy ,Ruby on Rails
I wrote this article today because it has become evident that there is a huge gap between the knows and the know-nots when it comes to Ruby, Rails and AJAX. This article provides a cursory look at three of today’s hottest web development terms.
If you’re an active member (or lurker) of any web development forums or newsgroups (or perhaps an avidSite5 Engineering Team fan), you have likely run into someone talking about Ruby on Rails—either to tout it as the greatest thing since sliced bread, to denounce it as a trendy and over-hyped technology, or, more likely, to ask what the heck it is and why people are so crazy about it. If you’ve previously glanced over these messages with the suspicion that their subject was of no interest to you and your work, chances are you were wrong. But fear not—In this article I’ll give you the elevator speech explanation of Ruby on Rails and AJAX.
If this is the first time you’ve ever heard the term “Ruby on Rails,” resist the urge to move on to the next article in an attempt to save yourself from reading about yet another impractical web technology. So, here’s the rundown:
1) Ruby (just “Ruby” by itself—not “Ruby on Rails”) is a programming language just like Perl, Python or PHP.
That’s it. It’s just another programming language. Albeit many Ruby programmers believe that the language has a more elegant and powerful syntax than its competitors, but when people talk about Ruby, they’re simply referring to a programming language that somewhat resembles a cross between Perl and Python.
If you’d like to learn the Ruby language with the help of a couple of cartoon foxes, head on over tothis site.
2) Rails (sometimes referred to as “Ruby on Rails”) is a web application framework written in the Ruby programming language. If you’re writing a Rails-based application, you’re writing Ruby code.
What the heck is a web application framework? That’s a rather complex question, but in very simple terms, a framework is like the “support structure” of a program. Believe it or not, the majority of the time that programmers spend writing big web applications isn’t actually spent on the specifics of the program’s functionality, but instead it’s spent doing much more general programming—writing reusable pieces of code that can be called throughout the main application. These reusable components are collectively referred to as the program’s framework.
Good frameworks make it much easier to add, update and modify parts of an application that do similar tasks. For instance, a very common operation in web-based programming is querying an SQL database and returning the results in a way that is meaningful to the rest of the program. The Rails framework includes a high-powered database access library called ActiveRecord that simplifies the process of using SQL databases from within an application. A few other common tasks for which Rails provides pre-written libraries include: form data validation, application templates, email sending and receiving, date and time formatting and manipulation, session and cookie management, and interactive client-side functionality in web pages with AJAX (read on to see what that means).
The Rails framework, while flexible enough to be used by virtually any kind of web (or even non-web) application, was actually born out of another programming project.David Heinemeier Hansson, the lead programmer for37signals, wrote the Rails framework to help him develop three web applications that the company develops:Basecamp,Backpack andTa-da List. David very generously made the decision to open-source the framework, and has served as the project’s maintainer since doing so. Rails has been featured on the popular technology news site Slashdot as well as technology publisher O’Reilly’s website (who, by the way, will be releasing a Rails book very soon).
The consequence of starting with a complete framework like Rails is that web application programmers can develop web applications much faster than if they were starting from scratch. The marketing for Rails claims that it lets you develop ten times faster than a programmer sans Rails. To really understand the power that Rails gives programmers, you should watch theRails video, which shows a Rails application being built from scratch in 15 minutes!
3) AJAX, or Asynchronus Javascript and XML, is not a single technology, but rather a methodology of using a combination of Javascript, the Document Object Model (DOM), and the XMLHttpRequest feature of modern browsers to make requests to the remote server and conditionally update page content between browser reloads.
Clear as mud, huh? I’ll go over it piece by piece.
One of the problems faced by web application programmers is that there really isn’t a way to provide a true “interface” in the sense that we’re used to with desktop applications. With a web application, the interface is actually a series of individual requests made to a web server. Without the use of cookies and special trickery by programmers, the web server wouldn’t have any way to determine if two requests were made by the same person, or by two different people. Imagine having to include your username and password on every single page of the Amazon.com website if you wanted it to “remember” your name, preferences and 1-click settings—pretty irritating to say the least. So in order to solve this problem, application developers invented several techniques for storing user information and program data between page requests.
Now web developers are going a step further. Rather than wait for the next full page request to update the page, through the use of a Javascript function known as XMLHttpRequest, web application programmers are making calls to the remote server from within a web page. By a “full page request,” I’m referring to what happens when you click on a link or type a URL in your browser’s address bar: the whole browser content area reloads with the new page. That’s how the web works—the new page replaces the old one (although it may be made to look like the previous page in order to give the impression that you haven’t left the site you’re on).
However a page using AJAX techniques will use Javascript code embedded in the page to make a request “asynchronously” (basically “in the background”) to the remote server and receive a response without your browser page reloading. One simple use of this technique is to have a text box to make repeated calls to the remote server as you type, and display the results in what appears to be a “drop down” menu below the text box. If you’ve ever used the Gmail address book or the new Google Suggest search tool (try it out at http://www.google.com/webhp?complete=1) you’ll see how handy just a pinch of AJAX functionality can be. If you want to see the mother of all AJAX tools, take a look at Google Maps and notice how the map seems to change without your browser reloading the page. That’s AJAX at its finest.
Now why does this matter if we’re talking about Ruby on Rails—a server side (as in, the code is run by the web server, not the web browser) programming language and framework? Rails happens to include an extensive library of AJAX functions that can be used without any Javascript knowledge. You use Rails functions from Ruby scripts and Ruby templates (which look very similar to PHP pages) and those functions automatically generate the Javascript that performs the AJAX magic. So by learning Ruby on Rails, you’re gaining the ability to use some veryadvanced Javascript techniques. A pretty nice deal!
The bottom line is that Rails is quickly sweeping through web development communities and converting many former zealots of other programming languages. Rails is too new to have many large-scale commercial applications that you can go out and drop into your website right away. However the first generation of viable Rails replacements for common programs (forums, blogs, CMS systems, etc.) should be ready within the next three months.
Meanwhile, web developers who are eager to try out Rails programming are begging their hosts to provide support for Rails-based sites (something that we completed support for here at Site5 just earlier this week). Over the next few months, expect to see announcements from many hosts and control panel systems boasting support for Ruby on Rails.
There is no doubt that Rails will be a fixture in the web development community for many years to come, and will give the established applications and programming languages an impressive run for their money. Keep an eye out for this next-generation platform—or better yet, beat the masses and get started developing your own Rails-based site today!
Additional Resources:
Ruby on Rails official website:http://www.rubyonrails.org/
Ruby language official website: http://www.ruby-lang.org/
An introduction to AJAX:http://www.adaptivepath.com/publications/essays/archives/000385.php