Slashdot Mirror


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."

26 of 187 comments (clear)

  1. Python Version of RoR by grayrest · · Score: 4, Interesting

    http://subway.python-hosting.com

    It's rough, but it's coming along.

    1. Re:Python Version of RoR by jellomizer · · Score: 3, Insightful

      It is always good to have two closly competing languages. Ruby and Python are so close in design it helps keep both on their toes. Some people consider Python and Perl to be competive but the language syntax is much more different, and often lead to more of a holy war debate on what is better. While I don't find this type of argument for Python vs. Ruby But I could just be looking in the wrong spots.

      --
      If something is so important that you feel the need to post it on the internet... It probably isn't that important.
    2. Re:Python Version of RoR by Colonel+Panic · · Score: 4, Insightful

      Wouldn't that be PoR?

      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...

    3. Re:Python Version of RoR by Colonel+Panic · · Score: 3, Funny

      Sorry...
      That should be 'immolation is the sincerest form of flattery'.

    4. Re:Python Version of RoR by Simon · · Score: 3, Insightful
      Being able to define natural looking domain-specific languages using Ruby's code blocks seems like something that would be very difficult in Python.

      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

    5. Re:Python Version of RoR by Paradox · · Score: 4, Informative
      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!"
      end
      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 }
      my_block.call "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
      block.call #Calls the associated block as a function
      end
      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:
      File.open( "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.
      --
      Slashdot. It's Not For Common Sense
  2. What is this? by Lovesquid · · Score: 3, Insightful

    Hmmm... nowhere in the summary does it tell what "Ruby on Rails" is, or why I should care about it, and with the server getting hammered, I can't RTFA to find out. How about including a 1-sentence summary of what the topic of any story IS before posting it, for those of us who don't already know everything there is to know about everything.

    1. Re:What is this? by JamesOfTheDesert · · Score: 5, Insightful
      It's a collection of Java Best Practices rewritten in a 'cool' geeky language. Nothing new....

      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

      % struts myAppName
      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.

      --

      Java is the blue pill
      Choose the red pill
    2. Re:What is this? by coldtone · · Score: 3, Insightful

      Halfway done?! You must be kidding!

      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.

  3. Any interesting projects? by elh_inny · · Score: 4, Interesting

    Has anyone actually done some interesting stuff that now works in a productive environment?

    1. Re:Any interesting projects? by elmartinos · · Score: 5, Informative
      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.
  4. Sounds exciting... by szlevente · · Score: 4, Interesting

    "A Rails web application can run under virtually any web server"
    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.

    1. Re:Sounds exciting... by zimba-tm · · Score: 3, Informative

      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 :
      www.basecamphq.com
      www.tadalist.com
      www.43thi ngs.com
      www.snowdevil.ca
      www.bellybutton.de

    2. Re:Sounds exciting... by rubycodez · · Score: 5, Informative

      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.

    3. Re:Sounds exciting... by drew · · Score: 3, Funny

      yeah, 'cause BeOS and MS-DOS are crucial platforms to support when you're developing an enterprise framework.

      --
      If I don't put anything here, will anyone recognize me anymore?
  5. Rails and other Rails tutorials by teidou · · Score: 5, Informative

    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.

    1. Re:Rails and other Rails tutorials by pamri · · Score: 3, Informative

      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.

  6. One thing has changed... by WWWWolf · · 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!

    1. Re:One thing has changed... by Tobias+Luetke · · Score: 4, 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...

  7. ROR rocks! by Pfhreakaz0id · · Score: 5, Interesting

    As a guy who has written db-driven web apps in ASP, asp.net ( alittle), perl CGI, plain JSP/Servlet and j2ee app server with EJB's (both with and without a persistence framerwork/Object-relational bridge), I can tell you ROR is my favorite. I've only been using it for two weeks on a part-time project. It's ... beautiful. I can't think of any way to describe it. It. Just. Works.

    And ruby is a really nice scripting language. You should check it out.

    1. Re:ROR rocks! by pepicek · · Score: 3, Interesting

      The best way to describe ruby and rails for me it's that you are writting programs for you to understand them, not for computer. It's really changing the way you think when you are programing. You have time to focus on bussiness problem rather than computer's. Even if you have Mac OSX and really love it :-).

  8. Agile Web Development With Rails by Ridgelift · · Score: 4, Informative

    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!)

    1. Re:Agile Web Development With Rails by Ridgelift · · Score: 3, Informative

      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 :-)

  9. Comparing RoR with Java solutions by MarkWatson · · Score: 4, Interesting

    I have worked through the RoR tutorial and re-implemented a simple admin web app that I originally wrote for a customer using JSPs and Tomcat. I must say that what took me 4 hours to write using JSPs and JDBC took about 30 minutes using RoR.

    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

    1. Re:Comparing RoR with Java solutions by dDrum · · Score: 4, Interesting

      There is a version of rails in java.
      It's called Trails and it uses spring, hibernate and tapestry.

      Site - http://trails.dev.java.net
      Tutorial - https://trails.dev.java.net/tutorial/"
      Trails in action - https://trails.dev.java.net/media/trails_withnarra tion.mov

      It's still beta but you can try it.

  10. Shortcomings of Rails by sean23007 · · Score: 3, Insightful

    I considered using Ruby on Rails for a large project I was doing, and found that though it was extremely easy to get started and do simple applications, it fails on more complicated databases. It does everything for you automatically, and you can easily write functions in Ruby that do the work of the database, but this is best only when the database isn't doing a whole lot itself except for holding data.

    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.

    --

    Lack of eloquence does not denote lack of intelligence, though they often coincide.