background preloader

Ruby

Facebook Twitter

Reference

Merb. Cruisecontrol. Deja vu all over again. Back when I was still programming Perl, one of the common mistakes that you’d see when people wrote lazily initialized object accessors was code like: Code written like this would trundle along quite happily, until you had an attribute where, say, the empty string or 0 were legal values for the attribute.

Deja vu all over again

The problems were especially painful when the default value wasn’t something that perl treated as false. The correct way of writing that code would be: Which is substantially uglier, but safe. Safety’s important, especially in building block code like accessor methods. Why déjà vu? Recently, the usually spot on Jay Fields wrote up the lazy initialization pattern for Ruby. Does that look familiar? This code is guaranteed to work in all circumstances. Going a little bit further… As Mark Jason Dominus has argued persuasively elsewhere, patterns are a sign of weakness in a programming language, so how can we go about incorporating this boilerplate code into our language. Trackbacks are disabled. Superators Add New Operators to Ruby. Rubinius. Blog Archives » Ruby on Rails megapost - Awesome Resources. Base - RailsHelp. Active Record objects don’t specify their attributes directly, but rather infer them from the table definition with which they’re linked.

Base - RailsHelp

Adding, removing, and changing attributes and their type is done directly in the database. Any change is instantly reflected in the Active Record objects. The mapping that binds a given Active Record class to a certain database table will happen automatically in most common cases, but can be overwritten for the uncommon ones. See the mapping rules in table_name and the full example in files/activerecord/README_rdoc.html for more insight. Creation Active Records accept constructor parameters either in a hash or as a block. User = User.new(:name => "David", :occupation => "Code Artist") user.name # => "David" You can also use block initialization: user = User.new do |u| u.name = "David" u.occupation = "Code Artist" end And of course you can just create a bare object and specify the attributes after the fact: Conditions Student.where(:grade => 9..12) Exceptions.

Starting Ruby on Rails: What I Wish I Knew. Ruby on Rails is an elegant, compact and fun way to build web applications.

Starting Ruby on Rails: What I Wish I Knew

Unfortunately, many gotchas await the new programmer. Now that I have a few rails projects under my belt, here’s my shot at sparing you the suffering I experienced when first getting started. Tools: Just Get Them Here’s the tools you’ll need. Don’t read endless reviews trying to decide on the best one; start somewhere and get going. Rails Tutorial: A cohesive book is worth dozens of hobbled-together online tutorials.InstantRails: A .zip file containing Ruby, Apache, MySQL and PHP (for PhpMyAdmin), packaged and ready to go.Aptana/RadRails (like Eclipse) or Ruby In Steel (like Visual Studio) for editing code.Subversion and/or TortoiseSVN for source control.Browse popular ruby on rails links on del.icio.us, Rails documentation and Ruby syntax & examples. But What Does It All Mean? Ruby Fleebie » Diving into ruby object model : Part 1.

So far I’ve talked about how everything was an object in ruby, even classes.

Ruby Fleebie » Diving into ruby object model : Part 1

I also wrote an article explaining what were the most important steps to follow when trying to understand ruby classes and objects. This wasn’t a bad idea, but it was a rather simplistic view. I think we’re ready to dive into the heart of the object model. Now my objective is not to give you a vague idea about how the ruby object model might work, I want to show you clearly what’s going on behind the scenes. Since I am not a fan of long posts, I have decided to split it in two parts. It’s not that the ruby object model is hard to understand, in fact it is quite simple and coherent, but in order to understand it you’ll need to be concentrated, open minded as well as having a decent understanding of dynamic languages.

Sebastian Kanthak - FileColumn - easy handling of file uploads i. Attention: I will be speaking at the Canada on Rails conference, which will be held on April 13th-14th in Vancouver, Canada. David Heinemeier-Hansson will be giving a keynote and there are a lot of other big names on the list of speakers . I'm honored to give a talk about file_column and developing plugins in general. This library makes handling of uploaded files in Ruby on Rails as easy as it should be. It helps you to not repeat yourself and write the same file handling code all over the place while providing you with nice features like keeping uploads during form redisplays , nice looking URLs for your uploaded files and easy integration with RMagick to resize uploaded images and create thumb-nails. Files are stored in the filesystem and the filename in the database. Example As you can judge a library best by looking at how to use it, here is a short example: Just make the "image" column ready for handling uploaded files ... class Entry < ActiveRecord::Base file_column :image end Top.