Part 2 of Ruby on Rails Tutorial Online
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."
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.
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 RubyOnRails.com. An good alternative tutorial is at http://rails.homelinux.org/.
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.
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!
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).
///<sig
Some answers for those who are lazy
:
:i ngs.com
== 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
www.basecamphq.com
www.tadalist.com
www.43th
www.snowdevil.ca
www.bellybutton.de
- http://www.43things.com/ Nice amazon-like community thingy
- http://www.basecamphq.com/ Online project management sofware
- http://www.tadalist.com/ Todo-lists
- http://www.snowdevil.ca/ Snowboard stuff
Although, the first 3 links are somewhat related.Open Source Alternatives
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.
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!)
Ruby on Rails Screencast
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.
Transcript show: self sigs atRandom.
[3, 4, 2, 6, 7, 8, 1, 12, 5].sort { |x, y|
if x >= 5 and y >= 5
y x
else
x y
end
}
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.
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 textdrive.com 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!
Slashdot. It's Not For Common Sense
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.
Yes.
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.
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.
Lack of eloquence does not denote lack of intelligence, though they often coincide.
list comprehensions are fun.
off the top of my head,
would be written in python as:
(which i personally find much more readable) and
would be written in python as:
and the find_all version just wouldn't have '[0]' at the end.
and the weird sort would be something like:
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:
most python programmers would shun that use of lambda though and do things in a slightly longer but more obvious fashion.
Smokey the Bear says, "Strip mining prevents forest fires!"
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.