What Is Ruby on Rails
Pages: 1, 2, 3, 4, 5, 6, 7
Action Mailer
Action Mailer is a simple facility for sending and receiving email in your web application. Here's a method that sends an email with an attachment:
# send email with attachment
def signup_notification(recipient)
recipients recipient.email_address_with_name
subject "New account information"
from "system@example.com"
attachment :content_type => "image/jpeg", :body => File.read("an-image.jpg")
attachment "application/pdf" do |a|
a.body = generate_your_pdf_here()
end
end
To learn more, see the Action Mailer API, and Chapter 19 of the book Agile Web Development with Rails.
Action Web Service
Action Web Service implements server-side support for the SOAP and XML-RPC web service protocols and makes it easy for you to create web service APIs and publish them via WSDL.
Here is part of the MetaWeblog API as implemented by Typo (open source weblog software written in Rails):
class MetaWeblogApi < ActionWebService::API::Base
api_method :getRecentPosts,
:expects => [ {:blogid => :string},
{:username => :string},
{:password => :string},
{:numberOfPosts => :int} ],
:returns => [[MetaWeblogStructs::Article]]
api_method :deletePost,
:expects => [ {:appkey => :string},
{:postid => :string},
{:username => :string},
{:password => :string},
{:publish => :int} ],
:returns => [:bool]
end
class MetaWeblogService < TypoWebService
web_service_api MetaWeblogApi
def getRecentPosts(blogid, username, password, numberOfPosts)
articles = Article.find_all(nil, "created_at DESC", numberOfPosts)
articles.to_a.collect{ |c| article_dto_from(c) }
end
def deletePost(appkey, postid, username, password, publish)
article = Article.find(postid)
article.destroy
true
end
end
This snippet shows only two of the seven API methods defined in this class by Typo.
To learn more, see the Action Web Service Manual.
Parting Thoughts
You can usually divide web application frameworks and the developers who use them into two distinct categories. At one end of the spectrum, you have the heavy-duty frameworks for the "serious" developers, and at the other end you have the lightweight, easy-to-use frameworks for the "toy" developers. Each of these groups generally regards the other with disdain.
One of the most interesting things is that Rails is attracting developers from both camps. The high-end developers are tired of the repetitive, low-productivity routine that they have been forced to endure, while the low-end developers are tired of battling a mess of unmanageable code when their web apps move beyond the simple. Both of these disparate groups find that Rails provides sustainable relief for their pain. I don't know about you, but I find this quite remarkable!
At the moment, Ruby on Rails barely captures a tiny percentage of web development projects. Yet it is rapidly gaining mind share, and many respected software development leaders have been testing the waters with Rails and publicly singing its praises.
Perhaps it's time that you too checked out Rails to see firsthand what the fuss is all about.
Acknowledgments
Most of the sample source code shown in this article came from the Rails API documentation, with permission.
Resources
- Official Ruby home page
- Official Ruby on Rails home page
- Ruby on Rails documentation
- Instant Rails, a one-stop Rails runtime solution containing Ruby, Rails, Apache, and MySQL, all preconfigured and ready to run. There's no installer; you simply drop it into the directory of your choice and run it. It does not modify your system environment.
- The Locomotive project is a quick start to Ruby on Rails development on Mac OS X, providing a sandboxed, no configuration, one-folder install of Ruby on Rails, SQLite, Lighttpd/Fastcgi, and much, much more.
- Rails mailing list
- Ruby-talk mailing list
- Agile Web Development with Rails
- Rolling with Ruby on Rails (Part 1 and Part 2)
- Ajax on Rails
Curt Hibbs has been a consultant to well-known companies like Hewlett Packard, Intuit, Corel, WordStar, Charles Schwab, Vivendi Universal, and more. He now works as a Senior Software Engineer for The Boeing Company in St. Louis.
Return to ONLamp.com.
You must be logged in to the O'Reilly Network to post a talkback.
Showing messages 1 through 21 of 21.
-
Great deal on hosting
2005-10-28 11:49:13 abnerDesign [Reply | View]
Those looking for Rails hosting may be interested in the DREAMRAILS promo ($97 off) at DreamHost (www.dreamhost.com) . A year of prepaid hosting can be had from $22.40.
-
Ruby on Rails is only one option
2005-10-26 11:30:03 teejay [Reply | View]
Lets be honest, if you are already using ruby then it's an obvious choice but every dynamic language has a decent MVC Framework these days.
Perl has two : Maypole (version 1.0 was released several months before the first version of Rails) and Catalyst (newer, less focus on pure MVC, more flexibility and metaprogramming).
Both allow you to utilise Perl's best of breed Template Toolkit (no other language has a templating system that can match it) as well as Class::DBI which provides a simple but powerful ORM to match that used by Rails.
Perl also offers several ORMs depending on your needs, dozens of plugins for Class::DBI, Maypole, TemplateToolkit and of course the CPAN with its selection of high quality code.
Finally you can't really compare the quality and maturity of Rails to struts, hibernate, etc. Rails and Ruby just aren't competitive with the Java equivilent if you are in a corporate environment. -
Ruby on Rails is only one option
2005-10-26 11:45:47 Curt Hibbs |
[Reply | View]
A agree that Ruby on Rails is jusrt one of many options. But I must a couple of corrections to your statements.
First, Ruby has an analog of Perl's DBI called Ruby::DBI. Rails' ORM is build on top of Ruby::DBI and operates at a much higher level of abstraction. Class::DBI is in no way a match for Rails' ActiveRecord.
Second, unless you need two-phase commits or distributed transactions, its Java that is not competitive with Ruby on Rails (unless you are competing for which needs to hire the largest number of developers). -
Ruby on Rails is only one option
2005-10-27 01:33:34 teejay [Reply | View]
I'll call your bluff on this. I know Class::DBI pretty well, I use it heavily because I am Lead Developer and Maintainer of the Maypole MVC Framework :)
Class::DBI not only matches but betters ActiveRecord, the availability of plugins and subclasses offer far more than ActiveRecord can, and it offers significantly more flexibility. Not once I have I seen some Rails, catalyst or other project using an ORM feature and thought 'that is neat, I wish CDBI could do that', it is far more likely to be the otherway around.
Hibernate is also more than competitive with ActiveRecord, if very different.
Furthermore Rails templating system simply cannot match Template Toolkit. Template Toolkit has been around for years longer, has dozens of plugins and even books about it.
Rails doesn't deliver best-of-breed anything, or break new ground other than in marketing and killer apps.
Once the hype of the type in this article dies down, Rails will have to compete on it's merits and is likely to be found wanting by users who have tried the alternatives. -
Ruby on Rails is only one option
2005-10-27 04:07:09 Curt Hibbs |
[Reply | View]
> Class::DBI not only matches but betters
> ActiveRecord, the availability of plugins and
> subclasses offer far more than ActiveRecord can,
> and it offers significantly more flexibility.
Fair enough.
> Hibernate is also more than competitive with
> ActiveRecord, if very different.
Hibernate is more flexible than ActiveRecord. This is both its blessing (when you need it) and its curse (when you don't).
> Furthermore Rails templating system simply
> cannot match Template Toolkit. Template Toolkit
> has been around for years longer, has dozens of
> plugins and even books about it.
The point is not being best-of-breed. The point is being focused on its target and avoiding feature feature creep.
> Rails doesn't deliver best-of-breed anything,
> or break new ground other than in marketing and
> killer apps.
Yes and no. I clearly stated in this article that Rails doesn't do anything new, in and of itself. What is new is its targeted, focused approach with all layers provided in a seamlessly matched set. It may not sound like much, but the synergy this achieves has a tremendous effect on productivity.
> Once the hype of the type in this article dies
> down, Rails will have to compete on it's merits
> and is likely to be found wanting by users who
> have tried the alternatives.
The first part has aready happenned. It has been tried by many who have used the alternatives. For type type of web app Rails targets, it has not not been found wanting -- to the contrary, it has been found to be a competitive advantage.
-
Ruby on Rails is only one option
2005-10-27 05:32:20 teejay [Reply | View]
I think you confused Class::DBI for DBI earlier in the thread. For the sake of clarity - Ruby's DBI is a clone of Perl's DBI. ActiveRecord is a fairly run of the mill ORM which clones Class::DBI.
I think all of the MVC frameworks written in dynamic languages offer a clean and well integrated set with varying levels of polish. Maypole certainly provides seamless working in it's default combination of Maypole/CDBI/TT and also Maypole/CDBI/Mason.
I think the synergy you describe is certainly available in any decent MVC framework.
The biggest deal for me about Rails is it's highly polished marketing, documentation and evangelism, combined with a handful of well designed and good looking applications.
People moving from Java and PHP backgrounds will certainly see a productivity gain for smaller projects (I think for larger more complex applications Java would be equally productive for different reasons), but that isn't the case for those comparing Maypole or Catalyst to Rails.
In fact as far as I know, nobody has even mentioned switching to Rails from Maypole or even compared them, the only defectors we have had have been to Catalyst.
Right now, there simply isn't much of a reason to move from any MVC to another - they all provide their own advantages and I don't think we'll see much of the switching you seem to think is happening. -
Ruby on Rails is only one option
2005-10-27 06:18:36 Curt Hibbs |
[Reply | View]
Yeah, I did mistake Class::DBI for DBI.
You make good points and are being entirely reasonable. Kudos for that!
The synergies that I talk about are not available in all MVC frameworks, well at least not the ones where you have to cobble together an MVC solution from multiple libraries (which is typical in Java).
I'm mostly see switching from Java and PHP, and some from Python. There might be some Perl switching (obviously not from Maypole :-), but I'm not personally aware of any particular instances.
Even though it may not seem like it, I'm not religious about Ruby or Rails. I am, however, very strong on productivity. I think Rails has this nailed at the moment, but that won't last forever.
I'm happy to see viable alternatives. Django looks promising, and I'll keep my eye on Maypole, too. -
Ruby on Rails is only one option
2005-10-27 07:51:08 teejay [Reply | View]
I haven't really had time to look at the python and PHP MVC's yet.. maintaining 1 MVC leaves little time to look at the others..
I'd love to be able to play with them all though. Maybe we need an OSS MVC workshop :)
Rails certainly leads on Killer Apps and many developers find ruby particularly productive - I think those you like python love ruby.
I'd love to see a good bakeoff or comparison between Rails, Maypole and Catalyst or others - would be very useful to show up weaknesses and strengths and hopefully find which are better suited to different applications.
I think the one to watch regarding breaking ground will be catalyst, which Leo and Leon built their competition winning mightyv on (http://use.perl.org/~acme/journal/27321).
I'm glad you managed to at least tone down the evangelism but I'm fed up with people talking up RoR as if there are no alternatives, the article only compares against Java or PHP entirely forgetting you get the same productivity with Perl and Maypole or Catalyst, falsely giving the impression that features are new and unavailable elsewhere.
At least it is far better than Bruce Tate's obvious zealousness .. at http://www.webservicessummit.com/Articles/MovingPastJava_2.htm,
The point is that Rails isn't very unique or innovative but your article and many others either accidentally or intentionally continue to give this impression.
Sorry for the whinge, I have a nasty flu, and am feeling old and grumpy as I'll be 30 on saturday :(
p.s. Evangelism aside, that is a very good article and gave a great intro to starting with ruby. -
Ruby on Rails is only one option
2005-10-27 08:14:53 Curt Hibbs |
[Reply | View]
> Sorry for the whinge, I have a nasty flu, and am
> feeling old and grumpy as I'll be 30 on saturday :(
You're still a young guy! I remember that I didn't really feel like I was an adult until I was 33 (if I had kids I'm sure I would have felt like an adult earlier). As evidence, I no longer wince when someone calls me "sir".
> p.s. Evangelism aside, that is a very good
> article and gave a great intro to starting with
> ruby.
Thanks!
-
Ruby on Rails is only one option
2005-10-27 01:47:20 teejay [Reply | View]
A useful for for comparing Rails and Hibernate is at http://theserverside.com/articles/article.tss?l=RailsHibernate
comparing Class::DBI at the same time shows AR offers nothing C::DBI doesn't do, and that CDBI options bring it closer to matching some of Hibernates features than AR. -
Ruby on Rails is only one option
2005-10-26 11:48:11 Curt Hibbs |
[Reply | View]
I don't know how my words got scramble! This first line above should have read:
I agree that Ruby on Rails is just one of many options. But I must make a couple of corrections to your statements.
-
seaside web framework
2005-10-18 15:11:33 martin schubert [Reply | View]
i am very happy to see pure object oriented and highly dynamic programming languages are gathering the attention they deserve. but in my opinion smalltalk and especially squeak plays at least an important role like ruby. there is an astonishing web framework called seaside which runs on the squeak platform. if you are fascinated by ruby on rails you should check out this one as well.
www.seaside.st ;-)
-
Quick Start with Ruby on Rails on Mac OS X
2005-10-15 21:36:53 raaum [Reply | View]
My Locomotive (http://locomotive.sourceforge.net) project is a quick start to Ruby on Rails development on Mac OS X, providing a sandboxed, no configuration, one-folder install of Ruby on Rails, SQLite, Lighttpd/Fastcgi, and much, much more. Perfect if you want to be using Rails within the next 5 minutes!
-
WebObjects?
2005-10-14 11:46:10 DanD. [Reply | View]
Ruby on Rails sounds very nice, but many of the parts sound very much like WebObjects and Enterprise Objects. Other than the obviously distinct features (Prototype, for example), how does Rails stack up against WebObjects and Enterprise Objects, which has been around for a decade, and four(?) years in it's current Java incarnation? Especially now that WebObjects is freely included in Apple's developer tools. I've tried Googling on this topic, and lots of people want to know the difference, but it seems the closest thing out there is a description of how to migrate from one to the other. It would be really great if O'Reilly could do a side by side comparison of the two.
-Dan
-
Ruby on Rails vs TurboGears
2005-10-14 11:43:04 pierrebai [Reply | View]
What I would love to know is the advantage of Ruby on Rails (RoR) vs TurboGears (TG). I've been learning and using TG for the past 4 days and as far as I can see they seem to provide the same functionality: MVC, templates (TG uses Kid), ORM (TG uses SQLObject), dynamic web and URL parsing (TG uses CherryPy), AJAX and JSON support, multi-DB support, Apache support, etc.
Ruby seems a bit more advanced (I didn't read anything in TG about generating from an existing DB, maybe it exists).
Anyone has experience with both? -
Ruby on Rails vs TurboGears
2006-01-17 10:50:15 ramdaz [Reply | View]
Yes SQL Object does support it. And the 0.9 rocks. TG will win back misguided Pythonistas -
Ruby on Rails vs TurboGears
2006-01-17 11:12:02 Curt Hibbs |
[Reply | View]
Well, I certainly hope so. Choice is a good thing.
-
that's cool
2005-10-13 21:30:11 errorter [Reply | View]
it should be "what is Ruby on Rails 1.0?" :)
http://slashdotcn.org/article.php/20051014113830208
-
Very nice!
2005-10-13 17:28:20 Robby Russell |
[Reply | View]
Thanks for the great overview of Ruby on Rails! It has changed my whole outlook on web programming and it hasn't even been a year yet!
-
Great article but....
2005-10-13 17:08:59 Oyku [Reply | View]
Great overview. Well done. If this article was published 2 weeks ago I'd spend much less effort to convince my collegues why we have to get on the wagon.
As someone who have spent the past 2 weeks writing nothing but rails code I've got a few comments to make.
First of all the Ruby issue. If you are like me you may well be thinking of "everything is fine, but what is this ruby thing?" I'll tell you what. I only knew a language names Ruby existed when I started playing with Rails. I was a bit cautious until I found Ruby the most comfortable scripting language I've ever used. Some features will make you feel almost at home if you are a Perl person like I am. If you have coded PHP and used to is you'll find Ruby much easier to use (yes, I'm serious) The object oriented features of the language will let you code as you think. Imagine that you are using the same language for both your PHP code and your Smarty templates. e.g.
Secondly, do not compare Rails with Zope. More than half of the people I've talked about Rails brought up this issue. Yes they are similar because both use (at least at the early stages of Zope) rather less known languages, but unlike Zope, which I believe you need to excell in Python to get the most out of it, Rails does not require that. It's nothing but a incredibly well architectured framework and surrounding tools to create web applications. A decent text editor is all you need.
Thirdly, you may like all the ideas but you are wondering how fast you'll get on track right? I can tell you that if you know at least 2 scripting languages and used it professionally like Perl and PHP you already know enough Ruby to survive. Following the Agile web development with Rails book you'll be writing real world apps in no time.
Here comes the BUT part of my comment. Rails is still in its early stages you may come accross some annoying problems and need to apply patches but don't fear they are very few if you ever come accross. Ruby is the same. Don't expect the CPAN richness and maturity from gems. You'll find yourself compiling ruby extensions yourself e.g ImageMagick for instance. But again there's no need to fear it's not only easy to do, but also worth the effort.
To summarize, Rails is hot. My Rails and Ruby books arrived 2 weeks ago and I've deployed a serious web apps on a 5 server cluster yesterday and guess what? The client is happy. It's not because that I'm fast, because Rails is very well designed and flexiable.
I can write pages on Rails (HINT HINT HINT: Ruby and Rails deserves an oreillynet site of its own I believe) but I hope this will help you decide what to expect from Rails and convice you to give it a try along with this great article.







I have implemented the "payroll" application from "Agile Software Development" in ruby. It took me 10 times less LOC than the author wrote it. Great isn' it.
Here is my post about it:
http://orbanbotond.blogspot.com/2008/01/ruby-on-rails-productivity.html