19 Rails Tricks Most Rails Coders Don’t Know New to Rails 3? Check out the Ruby on Rails 3 Tutorial book and screencast. A book and screencast series showing you how to develop and deploy industrial-strength Rails apps in a direct, step by step way. Please note that this post is over four years old - it's from 2006! When looking at my own Rails code and that of the community as a whole, I often see places where certain Rails techniques could have been used, but weren't. Benchmark logic in your controller actions - It's really easy. User.benchmark("adding and deleting 1000 users") do 1000.times do User.create(:name => 'something') x = User.find_by_name('something') x.destroy endend Of course, your code would be a lot better ;-) The regular SQL logs are not shown when within the benchmark sections. acts_as_nested_set - Almost everyone is familiar with acts_as_tree, but acts_as_nested_set snuck into Rails quietly. You can learn a little more here. Get lots of info about requests - Checking request.post?
0. Getting Started When you program a computer, you have to "speak" in a language your computer understands: a programming language. There are lots and lots of different languages out there, and many of them are excellent. In this tutorial I chose to use my favorite programming language, Ruby. Aside from being my favorite, Ruby is also the easiest programming language I have seen (and I've seen quite a few). When you write something in a human language, what is written is called text. code . If you come across something you don't understand, or you have a question which wasn't answered, write it down and keep reading! But first we need to download and install Ruby onto your computer. Windows Installation The Windows installation of Ruby is a breeze. In order to program, you need to be able to write programs and to run programs. The Ruby installer comes with a lovely text editor called SciTE (the Scintilla Text Editor). It would also be a good idea to create a folder somewhere to keep all of your programs.
74 Quality Ruby on Rails Resources and Tutorials Learning Rails from scratch can be a pain. But don't fret, this guide provides the best Rails resources the Web has to offer. Ruby on Rails is quickly becoming one of the most popular modern programming language framework combinations. Related Articles: Fortunately for you, we've compiled a list of the best Rails resources the Web has to offer. Installation Sometimes, the most time consuming part of learning a new programming language is simply installing a working version of the software. Manual Installation If you're interested in getting Rails to work on your own, you'll need to follow the following steps: Ruby – First you need to download Ruby. Why do all of the work when someone else will do it for you? Instant Rails – One-click Rails installer for Windows. These step-by-step guides will walk you through the installation process. How-tos Installation – If you get stuck, or want to try to install Ruby to a more obscure operating system, look here. Tutorials Beginner Tutorials Try Ruby!
Base64 Decode and Encode - Online A MiniTest::Spec Tutorial: Elegant Spec-Style Testing That Comes With Ruby Despite RSpec's awesomeness, Test::Unit remains the most popular Ruby testing tool out there outside of Rails apps. I've recently been code walking through a lot of Ruby libraries for my Ruby Reloaded course and the typical arrangement is Test::Unit, sometimes coupled with Shoulda or Contest for some extra syntactic sweetness. Part of the reason for Test::Unit's enduring popularity is its presence in the Ruby standard library but, also, its general 'lightness' and speed. When you're writing a large app, using a powerful full-featured system like RSpec has significant benefits (particularly stakeholder involvement in writing the specs). But when you're working on a library that might spread far and wide and is aimed solely at developers, the pros of Test::Unit shine through. Enter MiniTest Note: Ruby 1.8 users can run gem install minitest to get MiniTest too but it's not part of the standard library there. What Does MiniTest::Spec Look Like? Nothing too unusual there, I hope. Give It A Try
5. More About Methods So far we've seen a number of different methods, puts and gets and so on (Pop Quiz: List all of the methods we have seen so far! There are ten of them; the answer is below.), but we haven't really talked about what methods are. We know what they do, but we don't know what they are. But really, that is what they are: things that do stuff. So, did you take the quiz? So as I was saying, just as every verb needs a noun, so every method needs an object. puts 'hello '.+ 'world' puts (10.* 9).+ 9 hello world 99 It isn't very pretty, so we won't ever write it like that; however, it's important to understand what is really happening. warning : warning: parenthesize argument(s) for future version. And, of course, we still have puts and gets to explain. iCantBelieveIMadeAVariableNameThisLongJustToPointToA3 = 3 puts iCantBelieveIMadeAVariableNameThisLongJustToPointToA3 self.puts iCantBelieveIMadeAVariableNameThisLongJustToPointToA3 If you didn't entirely follow all of that, that's OK. pots desserts ? .
21 Ruby Tricks You Should Be Using In Your Own Code Writing for Ruby Inside, I get to see a lot of Ruby code. Most is good, but sometimes we forget some of Ruby's shortcuts and tricks and reinvent the wheel instead. In this post I present 21 different Ruby "tricks," from those that most experienced developers use every day to the more obscure. Whatever your level, a refresh may help you the next time you encounter certain coding scenarios. Note to beginners: If you're still learning Ruby, check out my Beginning Ruby book. 2009 Update: This post was written in early 2008 and looking back on it, there are a couple of tricks that I wouldn't recommend anymore - or to which extra warnings need to be added. 1 - Extract regular expression matches quickly A typical way to extract data from text using a regular expression is to use the match method. email = "Fred Bloggs <fred@bloggs.com>"email.match(/<(.*?) Ultimately, using the String#[] approach is cleaner though it might seem more "magic" to you. x = 'this is a test' x[/[aeiou].+? puts x == 10 ?
Blog — All about Ruby programming. The Wonderful Tech Wizards of Oz Photo by David Jackmanson / Flickr The Information and Communication Technology sector is the fifth highest paying career group in Australia, with entry salaries starting at $88,000 and median salaries of $100,000. This ranking is both because of, and contributes to, Australia’s growing IT leadership. Over 50 software companies are listed on the Australian Stock Exchange. The growth of technology centers created by governmental planners and business networks, such as the Bentley Technology Park in Western Australia (adjacent to Curtin University of Technology), the Digital Harbour at Docklands in Melbourne, and the Macquarie Park in Sydney (including the Research Park and Macquarie University), combined with respected universities and the roll-out of the National Broadband Network, all demonstrate the IT successes of the Aussies! School ‘Em at Home! And Hook ‘Em All Up!