Part 2 of Ruby on Rails Tutorial Online 187
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."
Python Version of RoR (Score:4, Interesting)
It's rough, but it's coming along.
Re:Python Version of RoR (Score:4, Insightful)
Re:Python Version of RoR (Score:1, Troll)
You're not really supposed to write big programs in Perl -- Perl is better suited for short tasks, anything that includes heavy string parsing and/or sysadmin chores.
[evil Perl zealot hat on] Python, on the other hand, serves as a poor excuse for a "real" language aimed for apps longer than several screenfuls of code -- but, it loses because of [XXXXX]. It's also likely to give you Cobol fingers.
In the above, [XXXXX] s
Re:Python Version of RoR (Score:2)
Re:Python Version of RoR (Score:5, Insightful)
Seriously, though, I really think that Ruby the language is part of what makes RoR so great. I'm not sure you can do a lot of the same stuff in Python as you can with Ruby. Being able to define natural looking domain-specific languages using Ruby's code blocks seems like something that would be very difficult in Python. But as they say, imiation is the sincerest form of flattery...
Re:Python Version of RoR (Score:4, Funny)
That should be 'immolation is the sincerest form of flattery'.
Re:Python Version of RoR (Score:4, Insightful)
Do you any examples of this in action? I mean a non-trivial example showing a Ruby block based solution for a problem that is clearly better than the more tradional (messy?) solution.
Impress me. :-)
--
Simon
Re:Python Version of RoR (Score:2)
Re:Python Version of RoR (Score:2)
Re:Python Version of RoR (Score:2)
Re:Python Version of RoR (Score:5, Informative)
Re:Python Version of RoR (Score:2, Informative)
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:
Re:Python Version of RoR (Score:2)
When you see a block of code like this in Rails:
What it does is take the schema for the People table, parse it, and actually re-open the Person class at runtime and adds the methods to support th
Or for Perl... (Score:2)
Re:Python Version of RoR (Score:2)
http://www.cherrypy.org/ [cherrypy.org]
BSD Licence, also based on MVC style design.
Re:Python Version of RoR (Score:2)
What is this? (Score:3, Insightful)
Re:What is this? (Score:2)
Ruby on Rails, the super productive new way to develop web applications
OK, that's helpful. Continuing...
Ruby is a pure object-oriented programming language with a super clean syntax that makes programming elegant and fun...
Rails is a open source Ruby framework for developing database-backed web applications. What's special about that? There are dozens of frameworks out there and most of them have been around much longer than Rails. Why sh
Re:What is this? (Score:1)
Re:What is this? (Score:2)
Re:What is this? (Score:1)
Re:What is this? (Score:5, Insightful)
Quite true. For example, Java Best Practice #1 is to avoid using long, detailed XML files for configuration, and instead use the programming languge itself, which is dynamically loaded and interpreted when needed.
Another Java Best Practice is to let the framework write the tedious boilerplate code for you. For example, in Struts, you just run
and you're halfway done writing your Web application.Here's one more Java Best Practice: Avoid expensive , complex application server software, and do rapid development using the Web server that is built into the standard library. Then deploy to the Web server of choice with no code changes or quirky vendor-specific API hacks.
Re:What is this? (Score:1)
Re:What is this? (Score:4, Insightful)
Being a java web developer, and using struts to build 3 different applications I have to say that enough is enough.
Struts is a very simple web framework, which will do several things for you.
Dramatically increase the size of your app.
Limit the functionality of your app.
Makes the code hard to read and follow. Just about everything runs though the struts config file.
The only benefit I see with struts is that is provides some clean definitions for code. (A place for display, a place for validation, a place for the work to be done) And gives you some tags to help with internationalization. (Just help mind you, if you need to have a totally different layout for a different language then, well you're screwed.)
I would only use struts again if I was writing an application that was to be localized and translated, and was working on a large team. Otherwise a well written set of JSP's will get the job done faster and will be easier to read.
Re:What is this? (Score:3, Informative)
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
Re:What is this? (Score:3, Informative)
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.
Re:What is this? (Score:2)
i guess the question is, does it make sense for your application to be continually figuring out what it's database schema is at runtime, when it usually changes so little once the app is developed. i can imagine for smaller projects with light loads and in RAD situations, this makes a lot of sense, because you're exchanging a little processing overhea
Re:What is this? (Score:2)
Yes, of course, and any claims that Rails eliminates config files are, um, over-statements.
But: Given that *no* tool magically pulls the database schema by psychic forces straight from one's brain, the next best thing is to use a library that at least encourages you to use the best tool for
Re:What is this? (Score:2)
Re:What is this? (Score:1)
"In Rolling with Ruby on Rails, I barely scratched the surface of what you can do with Ruby on Rails"
Re:What is this? (Score:2)
Re:What is this? (Score:2)
Amazing!
Ruby is great (Score:1, Informative)
Any interesting projects? (Score:4, Interesting)
Re:Any interesting projects? (Score:3, Informative)
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
Re:Any interesting projects? (Score:2)
Check out http://www.textdrive.com/
Re:Any interesting projects? (Score:5, Informative)
Re:Any interesting projects? (Score:1, Redundant)
Sounds exciting... (Score:4, Interesting)
Now that really made me curious. Is that really true, tried, and tested? If so, we need another bunch of tutorials about how to use Rails under Tomcat, Apache, etc. There is no way this framework will replace existing Java frameworks, but using it for prototyping is promising.
Re:Sounds exciting... (Score:3, Informative)
== 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
Re:Sounds exciting... (Score:2)
DB wise, it supports MySQL, PostgreSQL, SQLite, MS SQL Server, IBM DB2 and Oracle.
Re:Sounds exciting... (Score:5, Informative)
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.
Re:Sounds exciting... (Score:2)
Re:Sounds exciting... (Score:4, Funny)
Caveat (Score:2)
Your web server can run Rails if it does the following:
This is an awful lot of them, and Ruby runs on just about every platform used for web serving, so yeah. Rails could work most a
Rails and other Rails tutorials (Score:5, Informative)
For more info, see RubyOnRails.com. An good alternative tutorial is at http://rails.homelinux.org/ [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.
Re:Rails and other Rails tutorials (Score:4, Informative)
Re:Rails and other Rails tutorials (Score:2)
Rails is not really MVC -- The Controller part at any rate, the bane of every struts programmer, is entirely invisible in Rails. I suppose not having to deal with it yourself doesn't make it go away
Rails has a very clear MVC separation. (Score:2)
Excuse me? Uhh, the look is defined by the templates, and the controllers just do the setup and actions. Rails has a very clear separation of view and controller.
You define look in the templates and behavior in the controller. Sometimes, the behavior is just loading a group of database items into a class variable for display. Sometimes, it's more complex, involving things like redirection and database manipulation.
But you'd
What I really want... (Score:2)
And how about a good tutorial on Ruby itself? Most of us have no idea what this language is about.
One thing has changed... (Score:4, Informative)
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 [debian.org]!
Re:One thing has changed... (Score:3, Informative)
Re:One thing has changed... (Score:5, Informative)
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...
34 different packages (Score:3, Interesting)
The entire Ruby system isn't 3MB, either, if you're calling those 34 packages the system. The log4r package alone is 1.1MB, libqt-ruby is another 1.3MB, and libxmlparser-ruby is 0.8MB.
And Debian does have Ruby 1.8.2, I run Debian unstable and I've bee
Re:34 different packages (Score:2)
And Debian does have Ruby 1.8.2, I run Debian unstable and I've been using 1.8.2 for a while now.
Try telling that to my web host. They (sanely) use Debian Stable on their servers. Debian Stable only includes Ruby 1.6.7. Why should they use Debian Unstable on production servers?
Re:34 different packages (Score:2)
Of course, they may not realize that. Similarly, it seems to be tough to find a web host that offers ordinary people J2EE...
Re:34 different packages (Score:2)
Re:One thing has changed... (Score:3, Informative)
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:
Re:One thing has changed... (Score:2)
Re:One thing has changed... (Score:2)
ROR rocks! (Score:5, Interesting)
And ruby is a really nice scripting language. You should check it out.
Re:ROR rocks! (Score:3, Interesting)
Re:ROR rocks! (Score:1, Interesting)
Re:ROR rocks! (Score:2)
Re:Stored procedures? (Score:2)
Agile Web Development With Rails (Score:5, Informative)
One of the big problems with Ruby on Rails [rubyonrails.com] is that it [rubyonrails.com] is [rubyonrails.com] well [rubyonrails.com] documented [rubyonrails.com], 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 [pragmaticprogrammer.com] 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!)
Re:Agile Web Development With Rails (Score:2)
Re:Agile Web Development With Rails (Score:2)
It's current up to 0.10, the latest version. David Heinemeier Hansson, the author of Rails, is also on the review team and seems to be good friends with Dave Thomas. So I think it's fair to say the book will be faily up to date, bu
Re:Agile Web Development With Rails (Score:2)
Ah; sounds like this is getting closer to Struts land: Great tool, but to really understand it you need to buy a book.
Or no?Re:Agile Web Development With Rails (Score:4, Informative)
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
Re:Agile Web Development With Rails (Score:2)
Comparing RoR with Java solutions (Score:5, Interesting)
A big advantage that Ruby and Python have over Java is that they are dynamic languages that makes it not too difficult to write a database wrapper class that dynamically looks at database/tables meta data and generates access methods on the fly. Java Tails (using XDoclet market tags) can't really compete.
I really love the full J2EE stack for developing large scalable web applications but I am now looking at alternatives for creating smaller systems much more quickly.
BTW, I really like RoR's templating scheme: much like JSPs in syntax (JSP non-XML syntax, that is) but do to Ruby's much terser notation for enumerating collections, the the templates tend to look a little cleaner.
For Python, I really like the light weight CherryPy web application framework. I plan on checking out Python Subway also when I have some time.
-Mark
Re:Comparing RoR with Java solutions (Score:4, Interesting)
It's called Trails and it uses spring, hibernate and tapestry.
Site - http://trails.dev.java.net [java.net]
Tutorial - https://trails.dev.java.net/tutorial/" [java.net]
Trails in action - https://trails.dev.java.net/media/trails_withnarr
It's still beta but you can try it.
Re:Comparing RoR with Java solutions (Score:3, Informative)
Re:Comparing RoR with Java solutions (Score:3, Interesting)
I'm not sure that Java can be used to replicate Rails. It might be possible, but it would probably mean abandoning a lot of existing infrastructure. Ruby does a lot of very clever/strange things, like dynamically adding methods to classes based off database schemas. The best we've seen Java
Re:Comparing RoR with Java solutions (Score:2)
They also try to replace Rail's ActiveRecord with hibernate which actually generates the OR code before compiling and not during run time meaning recompilation for every database change.
Just to put trails into perspective.
Rails picks up all changes to files immediately as long as you are in the development environment.
Trails is just flattering itself with comparing itself to rails.
Rails got me curious about Ruby (Score:3, Interesting)
Re:Rails got me curious about Ruby (Score:2)
Personal Testimonial (Score:2)
If Rails had been around when I first started the site, I would have saved hours upon hours of development time. Rails is an am
This is an amazing technology (Score:3, Informative)
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!
Re:This is an amazing technology (Score:2)
How much did you know about OO before you started? I've never had to touch it before.
MOD PARENT UP! (Score:2)
Shortcomings of Rails (Score:4, Insightful)
My database is in PostgreSQL, and uses a lot of dynamically named tables and schemas, as well as many trigger functions written in pl/pgsql. In order to get RoR to work, I found that I was going to have to edit the framework itself extensively, and would still be hampered by the slowness of Rails, which I found to be unforgivable.
I ended up having to design my own framework in Python, which can handle the most complicated databases without any more trouble than the simplest. The construction of the pages now takes a little more time than it did in Rails, but pages that used to take over a second to load are now instantaneous.
That said, I translated a small web app from Rails to my own framework, and the translation took less time than it did to write it in Rails in the first place and ran a lot faster, but that's because the design was done in Rails. I'd say that Rails is really good for prototyping small applications and getting them working really quickly, and then translating them to another framework for production becomes quite simple.
For non-trivial web applications, Rails has the problem of being optimized for ease of use, not for complete control. Note that I'm not trolling, or saying Rails has no use. Just that I found that it wasn't sufficiently capable for what I was trying to do with it.
Re:Shortcomings of Rails (Score:3, Interesting)
Also, AR has gone through some extensive changes in the last release, it may better suit your purposes now.
Keep in mind that it's still a fairly new framework. It will only get better!
Re:Shortcomings of Rails (Score:3, Informative)
Re:Shortcomings of Rails (Score:2)
Re:Shortcomings of Rails (Score:3, Interesting)
Re:Shortcomings of Rails (Score:3, Interesting)
If you're regularly dynamically creating and nameing tables, that sounds like you're abusing SQL to create trees and other arbitrarily nested hierarchies. Assuming Oracle and it's tree extensions isn't an option, maybe you should reconsider using an RDBMS for a tree-based back end? Or maybe you're doing something totally different, in which case just ignore me.
Re:Shortcomings of Rails (Score:3, Interesting)
The design of the database drew high
Re:Shortcomings of Rails (Score:3, Interesting)
Unless you enjoy having to explain yourself over and over.
Re:Shortcomings of Rails (Score:2)
Re:Shortcomings of Rails (Score:2)
There are some types of applications in which you cannot know at the time of writing the application what data is needed to be stored beyond a few common fields - say you're creating an inventory system and you need to be able to have it expand to contain information about new products and can't know in advance what special information you might need beyoun
Re:Shortcomings of Rails (Score:2)
Re:Ruby? (Score:2)
Yes, Ruby is that good. Rails is a very nice framework, and it does things that you couldn't do easily in other languages (and that includes Python).
As for editor commands, didn't you know only Emacs users get into heaven?
Re:Ruby? (Score:2)
It might be best not to learn Ruby first. If you were to learn it first, learning Java afterwords would be incredibly painful. Nothing makes you realize how bad Java is like learning Ruby.
VB isn't so bad, I guess, but I'd rather use Ruby and the FX toolkit for those kinds of simple script apps. But Ruby does have an amazign set of winapi bindings as part of the standard library. You might want to elevate it above VB.
Re:Ruby? (Score:2)
Re:Ruby? (Score:2)
Frameworks closely tied to languages, WHY (Score:3, Insightful)
Indeed. Why can't somebody make a fairly language-neutral framework? Why are all the UI frameworks so tightly bound to specific languages and why do people accept that?
Things like data/field dictionaries, screen descriptions, UI widget attributes, and event handling frameworks don't need to be closely tied to specific languages because they are mostly declarative in nature, so why are they in practice?
It just does not seem
Re:Frameworks closely tied to languages, WHY (Score:2)
Re:Frameworks closely tied to languages, WHY (Score:2)
In brief order: All widely used UI frameworks with the exception of the Windows API support declarative mechanisms, Windows to do so in the still-vaporware longhorn, all of them including Windows have bindings in enormous varieties of languages.
We never divorced database usage from being language-specific - it's done exactly the same way GUI is, with language-specific wrappers, often over other generic wrappers. There's a common query language which is sadly not all that common after all.
The "best