What Is Ruby on Rails

来源:百度文库 编辑:神马文学网 时间:2024/04/28 02:02:51

What Is Ruby on Rails
byCurt Hibbs
10/13/2005Ruby on Rails
Ruby on Rails is a web applicationframework written inRuby, a dynamically typed programming language similar to Python, Smalltalk, and Perl.
In This Article:
High productivity and reduced development time
How does Rails do it?
Rails components
General features
Active Record
Action Pack
Action Mailer
Action Web Service
Parting thoughts
It has been just over a year since the public debut ofRuby on Railson July 25, 2004. In this short time, Rails has progressed from analready impressive version 0.5 to an awe-inspiring, soon-to-be-releasedversion 1.0 that managed to retain its ease of use and highproductivity while adding a mind-boggling array of new features. Thisarticle introduces the components of the upcoming Ruby on Rails 1.0 andshows you what the fuss is all about.
I don‘t intend to teach you how to use Rails to write web applications. For that, you probably ought to start withRolling with Ruby on Rails Revisited andRolling with Ruby on Rails Revisited, Part Two. This is an introduction and road map to the many features of Rails.
At the feature level, Ruby on Rails doesn‘t offer anythingnew. Existing web application frameworks have done it all before.What‘s the big deal, then? The difference lies in how Ruby on Railsdoes it. When you can finish simple web apps in days instead of weeksand more complicated web apps in weeks instead of months, people notice!
This newfound attention would be short-lived if the resultingweb apps were messy and hard to maintain or extend. Fortunately Ruby onRails actually facilitates good programming practices, which leads towell-factored and easily maintained code.
The attention would also be short-lived if Ruby on Rails hadno depth--that is, if once you tried to use it for anything beyond thesimplest of web applications, you suddenly found yourself hitting awall, unable to proceed due to inherent limitations. Experienceddevelopers who know their way around the Web have repeatedly reported that this is not the case with Rails. For example, Tomcat, Ant, and the Servlet API authorJames Duncan Davidson recently wrote:
Rails is the most well thought-out web developmentframework I‘ve ever used. And that‘s in a decade of doing webapplications for a living. I‘ve built my own frameworks, helped developthe Servlet API, and have created more than a few web servers fromscratch. Nobody has done it like this before. That‘s not to say theygot it all right. It‘s by no means "perfect". I‘ve got more than a fewnits and picks about how things are put together. But "perfect" isn‘tthe point. The point is that it gets you up and going fast and hasplenty of depth to keep you going. And Rails does that very well.It may be hard to believe that this is possible without asignificant downside. Fortunately, you don‘t have to take my word forit (or anyone else‘s). You can easily prove it to yourself in a day orless by going through aRuby on Rails tutorialand then developing a modest web application of your own choosing.After all, seeing is believing! If you don‘t want see yourself beamazingly productive, you can always watch someone else do it in thenew Rails video.
Like a good recipe, Rails helps you achieve this new levelof productivity by combining the right ingredients in the rightamounts. Here are a few of the most important ingredients that makeRails what it is.
Ruby
Much of the power of Rails comes from the Ruby programming language. Ruby‘s unique design makes it easy to createdomain-specific languages and to dometaprogramming. Rails takes full advantage of this.
Full-stack MVC framework
Rails is anMVC(model, view, controller) framework where Rails provides all the layersand they work together seamlessly. Other frameworks often implementonly part of the solution, requiring thedeveloperto integrate multiple frameworks into the application and then coercethem into working together. (For example, a Java developer might useHibernate, Struts, and Tiles to get full MVC support.)
Convention over configuration
Convention over configuration means an end to verbose XMLconfiguration files--in Rails, there aren‘t any! Instead of XMLsit-ups, a Rails application uses a few simple programming conventionsthat allow it to figure everything out through reflection anddiscovery. For example, Rails uses intelligent reflection toautomatically mapdatabase tables to Ruby objects. Your application code and your running database already contain everything Rails needs to know.
Less code
Following the simple Rails programming conventions does morethan just eliminate the need for configuration files. It also meansthat Rails can automatically handle myriad lower-level details withoutyou having to tell it to do so. This means that you write fewer linesof code to implement your application. Keeping your code small meansfaster development and fewer bugs, which makes your code easier tounderstand, maintain, and enhance.
Generators
Rails‘ use of runtime reflection and metaprogrammingeliminates much of the boilerplate code that you would otherwise haveto create. You can often avoid what little boilerplate code remains byusing the built-in generator scripts to create it for you. This leavesyou with more time to concentrate on the code that really matters--yourbusiness logic.
Zero turnaround time
The typical development cycle for testing a change to a webapp has steps such as configure, compile, deploy, reset, and test. Thisis very time consuming. The Rails development environment has none ofthis. You simply make a change and see it work. Don‘t make the mistakeof dismissing this as a minor point. It‘s hard to overstate how muchthis improves productivity and helps you maintain a creative flowwithout interruption.
Scaffolding
Rails can automatically create a full set of CRUD (Create,Retrieve, Update, and Delete) operations and views on any databasetable. This scaffolding can get you up and running quickly withmanipulating your database tables. Over time, you can incrementallyreplace the generated CRUD operations and views with yourown--presumably much prettier and more functional.
Pages: 1,2,3,4,5,6,7
Next Page