Forgot your password?
Programming IT Technology

Part 2 of Ruby on Rails Tutorial Online 187

Posted by Zonk
from the productive-coding dept.
An anonymous reader writes "Curt Hibbs has released Part 2 of his tutorial Rolling with Ruby on Rails to the O'Reilly ONLamp site. The first part was published in January. Topics covered are database transactions, callbacks, unit testing and caching." From the article: "In Rolling with Ruby on Rails, I barely scratched the surface of what you can do with Ruby on Rails. I didn't talk about data validation or database transactions, and I did not mention callbacks, unit testing, or caching. There was hardly a mention of the many helpers that Rails includes to make your life easier. I can't really do justice to all of these topics in the space of this article, but I will go into details on some of them and present a brief overview of the rest, with links to more detailed information."
This discussion has been archived. No new comments can be posted.

Part 2 of Ruby on Rails Tutorial Online

Comments Filter:
  • Ruby is great (Score:1, Informative)

    by boeserjavamann (655642) on Friday March 04, 2005 @10:43AM (#11843905) Homepage
    too bad there isn't the big fellowship right now (besides japan, where it is bigger than python, whatever that means ;) i think its the most clean and powerful oo-scriptings language available.
  • by teidou (651247) <tait.fitis@com> on Friday March 04, 2005 @10:48AM (#11843956) Homepage
    To explain Ruby on Rails, I could say it is a highly integrated model-view-controller type web application framework. That would be like saying a Ferrari is a 4 wheeled internal combustion vehicle: true, but misses the point.

    For more info, see An good alternative tutorial is at [].

    There are even better introductory materials coming. Dave Thomas (of Pragmatic Programmers) is working on a Rails book, chapters are being reviewed presently.

    Rails is powerful an flexible. More importnatly, it's a lot of fun. If you are a programmer who want to enjoy web-based application development, please do take a look at Rails.
  • by WWWWolf (2428) <> on Friday March 04, 2005 @10:49AM (#11843968) Homepage

    When the part one was published, I had severe problems getting Rails to work in Debian. There was a lot of really odd tools that needed to be installed and all that. Rails web page had tons of Ruby packages that I was pretty sure I didn't need...

    But one thing has changed since then: Rails is now in Debian unstable []!

  • by Nik13 (837926) on Friday March 04, 2005 @10:54AM (#11844013) Homepage
    Last time when Pt1 of the the article came out, in the discussions on /. some sites were pointed out (seemed like decent sites too).

    I've been meaning to get around to add RoR to my apache (XAMPP) setup to try it out. Most of what I do at work is ASP/ASP.Net and I've been looking for something else (not to fully replace them, but perhaps as a complement). I'm not big on php, but it has it's uses and followers (I use it on some small websities with cheap hosting). J2EE isn't my definition of fun (although it's robust and all).

    From what I had seen, RoR seemed pretty promising (and it keeps getting better they say), but I'll have to dig deeper to see it's full power. The only problem I can see now is finding some decent hosting for that, preferably cheap (RoR *with postgresql* to make things worse).
  • by zimba-tm (598761) on Friday March 04, 2005 @10:55AM (#11844020) Homepage
    Some answers for those who are lazy

    == ROR runs and was tested under :
    Apache + CGI
    Apache + FCGI
    Apache + mod_ruby
    Lighttpd + FCGI
    WebRick (ruby server)

    OS : Linux / Window / OSX / *BSD

    == Real-life examples :
  • by elmartinos (228710) on Friday March 04, 2005 @10:56AM (#11844026) Homepage
    Shure! Even though Ruby on Rails is really very young, there are a few commercial sites that use it already. Here are a few links: Although, the first 3 links are somewhat related.
  • by rubycodez (864176) on Friday March 04, 2005 @11:24AM (#11844237)
    No way this framework will replace existing java frameworks

    There is actually a chance it may become a mainstream way of building an enterprise framework. There is a very cool new bytecode Ruby virtual machine and just-in-time compiler (YARV), and the next generation of Ruby, Ruby 2, will support native OS threading. Unlike Java, the source for Ruby is and will be completely open & transparent. Ruby can run on platforms where java can't, like BeOS and MS-DOS.
  • by pamri (251945) on Friday March 04, 2005 @11:27AM (#11844259) Homepage
    Another great resource is the Ruby on rails weblog [] which has links to more tutorials, job postings about rails, updates, etc., There's also an updated video [] tutorial on building a weblog.
  • by pamri (251945) on Friday March 04, 2005 @11:39AM (#11844372) Homepage
    Actually, rails/any ruby library/app/whatever is quite easy to install if it is available on ruby gems and you have installed ruby gems. ruby gems [] is sort of like apt for ruby. Once you install gems, to install rails, all you have to do is, gem install rails and gem uninstall rails to uninstall rails. Although you are unlikely to need it. :-D
  • by Ridgelift (228977) on Friday March 04, 2005 @11:47AM (#11844451)
    Dave Thomas' new book "Agile Web Development With Rails" [] is due out in July. It's really, really good so far (I'm one of the lucky ones who is helping review it). My perspective is a person who knows very little about databases, web application development and no previous knowledge of Ruby, the language that Rails is built on.

    One of the big problems with Ruby on Rails [] is that it [] is [] well [] documented [], but a lot of it is API's and reference documentation. Dave's new book has an excellent tutorial which is the best thing I've seen written so far about RoR for newbies, and promises to go into the depth and detail similar to his Pickaxe [] book.

    If you've previously looked at RoR and were disillusioned because you just weren't "getting it " or didn't want to slug through the technical documentation, I encourage you to keep an open mind and wait until Dave's book is released. I'm finally getting over the hump with RoR and I now see what all the fervour is about.

    (Oh, don't ask me to post or send copies of his drafts, 'cause I ain't gonna!)
  • by Tobias Luetke (707936) on Friday March 04, 2005 @11:52AM (#11844477)

    Please don't make this sound like an rails or ruby issue. Debian really blew it on packaging ruby. Most of the system related problems which come up in #rubyonrails are related to debian linux installations.

    How did they come up with the brilliant idea to split the standard library into 34 different packages? I just can't see how something moronic like this can even get started considering that a standard library is all about raising the status quo of the language by providing some shoulders to stand on so people can reach for higher goals.

    Keep in mind that ruby has no dependencies at all. All dependencies are optional and the libraries using them (tk,x11, readline) fail gracefully with exceptions when the parts are not installed. Not so if the entire library is missing, this will cause a runtime exception with cryptic error message which rails will never be able to handle. Also ruby is tiny the entire package is 3mb!

    I heard they are talking about improving the situation by adding a "virtual package" for ruby which contains all 34 seperate packages

    Future in Debian terminology is traditionally not soon and thats a fix feeble fix considering all they need to do is to put all 3mb of ruby in one package

    Anyways the point is fairly moot now since debian doesn't have ruby 1.8.2 anyways which is required for the latest rails

    Luckily its easy to install ruby by hand. And I heard gentoo and freebsd install pretty easily too...

  • by cortana (588495) <sam@[ ] ['rob' in gap]> on Friday March 04, 2005 @01:01PM (#11845174) Homepage
    $ cat /var/lib/apt/lists/ sarge_main_binary-i386_Packages | grep-dctrl -n --field=Package ruby --show=Size

    Summing the output, yeilds 31806976 bytes or 30 MB.

    $ aptitude show rails
    Package: rails ...
    Depends: ruby (> 1.8), ruby ( 0.10.7),
    libyaml-ruby (> 1.8.2), rdoc (> 1.8.2), libtest-unit-ruby (> 1.8.2),
    libdrb-ruby1.8, libsoap-ruby1.8, libxmlrpc-ruby (> 1.8)
    Recommends: libwebrick-ruby1.8, irb (> 1.8)
    Suggests: libapache-mod-ruby
    Description: MVC ruby based framework geared for web application development ...

    If you see a dependancy missing from that list, please file a bug.
  • by jimm (5532) <jimm AT io DOT com> on Friday March 04, 2005 @01:08PM (#11845235) Homepage
    When you watch the "Trails in action" movie be aware that each time he does a redeploy, the ant task takes about 37 seconds. With Rails, it's about one second.
  • by Ridgelift (228977) on Friday March 04, 2005 @01:46PM (#11845596)
    Am I the only one concerned that the reviewer for a book on web development using ruby admits he knows next to nothing about web development, databases, or ruby?
    I'm one reviewer amongst 22. I would say all the rest of the reviewers are much further along than I am, including DHH who wrote Rails.

    Dave Thomas is looking to write a book that will help people learn Rails. My big contribution other than grammatical and spelling errors is "Hey Dave, I don't understand this section you say is easy".

    To me, it's smart to let the uninitiated in so he can see if he's reaching part of his target audience: the ignorant :-)
  • by Anonymous Coward on Friday March 04, 2005 @01:49PM (#11845631)
    [3, 4, 2, 6, 7, 8, 1, 12, 5].sort { |x, y|
    if x >= 5 and y >= 5
    y x
    x y

    This sorts the array in the ascending order up to 5, and in the descending order after that, which gives [1, 2, 3, 4, 12, 8, 7, 6, 5]. This is a very simple example, but it would be less nice without blocs. Then you have more interesting cases, like:

    [1, 3, 7].collect { |x| x+1 }

    Which gives [2, 4, 8]. The result array is built by taking every element of the first array and applying the bloc to it. Not convinced ?

    [3, 4, 12, 76, 2].find { |x| x > 4 and x.modulo(2) == 0 }

    Gives 12, of course. But by using the same bloc with find_all instead of find, you get [12, 76].

    Of course, it's nothing new. You could get an equally nice syntax by using a functional language. But to my mind, ruby brings you the best from OOP and the best front functional programming. I just wish it was faster.
  • by badboy_tw2002 (524611) on Friday March 04, 2005 @01:50PM (#11845645)
    I don't normally write cheerleading testimonials, but its also rare I find something this cool that I want to gush about it.

    The first tutorial (I saw it right here on Slashdot!) got me curious about RoR. I went home and installed it that night. A couple weeks later (total of maybe 10 hours invested) I had completely converted my community website over to rails (from a servlets site), and am launching it fairly soon. The funny thing is, the actual code to drive this thing is really small. No boring, repetative database code, automatic validation, lots of helpful classes (authentication is downloading a new package and running a make script). Things in the tutorial make it look like you're limited to standard naming conventions, but I assure you that you can override everything if you've got an existing database that doesn't match the RoR naming scheme.

    I've found the community very helpful. Hosting is a bit limited now, but I'm getting a account soon to get my new site up and running.

    This is definately worth an install and the 20 minutes it takes to do the tutorial, check it out!
  • by Paradox (13555) on Friday March 04, 2005 @02:34PM (#11846082) Homepage Journal
    I can't impress you, sorry. But I can say that Ruby blocks are a powerful tool that are very flexible and useful. Ruby iterators are the showcase of this tool, and they're something you use every day in ruby. For example:
    ary = [1,2,3,4,5] # Example Array
    ary.each do |val| # Begin a block
    puts val.to_s + " was here!"
    Blocks can be used inline as above, or turned into true closure-bearing functors like so:
    my_block = lambda { |x| puts x.to_s was here } "Kilroy"
    ary = [1,2,3,4,5]
    ary.each &my_block
    You can write higher order functions that accept lexical blocks trivially. For example:
    def my_hof( &block )
    yield # Calls the associated block within scope #Calls the associated block as a function
    Also, ruby's blocks are used to do neat things like ensure things happen at the end of an operation. File I/O is the classic example. Check out how Ruby's library ensures your file closes: "somefile.txt", "w" ) do |handle|
    handle.puts "This is text in the file."
    end # File is ensured to be closed now
    This is just a small sample of what Ruby's standard lib does with blocks. They're really quite useful. They're like Lisp's lambdas but with a cleaner syntax when used inline.
  • Re:What is this? (Score:3, Informative)

    by swimmar132 (302744) <{joe} {at} {}> on Friday March 04, 2005 @02:58PM (#11846337) Homepage
    RoR replaces maintaining long detailed XML configuration files with maintaing long, detailed database specific sql files.

    No, RoR's models don't come from maintained SQL files. I believe it uses reflection to dynamically build the models.

    Using RoR, you create a table and let Ruby dynamically determine a bunch of information about relationships and data types and then you access various properties of this data.


    You are also forced to use RoR's Object model (You have to extend ActiveRecord, correct?)

    No. You can use the other components of Rails (ActionPack and the Web Service portion) without using ActiveRecord.

    Using something like Hibernate, you write an object, then do something do describe it (Java Annotations, XDoclet markup, tedious XML configuration file) and It can create the DDL/alter tables on the fly for you, and you are not forced to extend any object.

    That's probably true, I haven't worked with Hibernate. But with Rails, you make a change to the DB table, and the model instantly reflects that change.
  • by sean23007 (143364) on Friday March 04, 2005 @03:14PM (#11846521) Homepage Journal
    I don't mean to say that Rails has no uses. It definitely seemed to be wonderful for a certain subset of applications. However, the amount of work it would have taken to rewrite ActiveRecord such that it would be compatible with my database was roughly equivalent to the amount of work it would take to completely implement my own solution. I simply decided to do the latter. Perhaps I should have written an AR replacement that would have been enough for my database, because that certainly would have advanced Rails greatly. If someone else does that, my biggest complaint about Rails simply disappears.

    Bear in mind, however, that it feels really good to implement an entire framework yourself. While developing my application, I feel like DHH must have while he was writing Basecamp. It's a great feeling.
  • by thraxil (54926) on Friday March 04, 2005 @03:37PM (#11846735) Homepage

    list comprehensions are fun.

    off the top of my head,

    [1,3,7].collect { |x| x + 1}

    would be written in python as:

    [x + 1 for x in [1,3,7]]

    (which i personally find much more readable) and

    [3,4,12,76,2].find { |x| x > 4 and x.modulo(2) == 0 }

    would be written in python as:

    [x for x in [3,4,12,76,2] if x > 4 and (x % 2) == 0][0]

    and the find_all version just wouldn't have '[0]' at the end.

    and the weird sort would be something like:

    [3,4,2,6,7,8,1,12,5].sort(lambda x,y: ((x >= 5 and y >= 5) and cmp(y,x)) or (cmp(x,y)))

    except that python's sort is in-place, so you'd really want to have that list in a variable if you intended to do anything with the results:

    l = [3,4,...]

    most python programmers would shun that use of lambda though and do things in a slightly longer but more obvious fashion.

  • Re:What is this? (Score:3, Informative)

    by arkanes (521690) <> on Friday March 04, 2005 @06:18PM (#11848586) Homepage
    My point is merely that the database schema does not magically appear from nowhere.

    It is magically pulled from the database. Lots of existing OR mapping tools can do this, including Java ones, but lacking Ruby's dynamic nature it's done as an extra pre-compilation step. Rails can do it at runtime.

Their idea of an offer you can't refuse is an offer... and you'd better not refuse.