Populating form values through a link in Rails

Today I was asked to help with creating a link on a website that should take the user to a different page where a form should be filled out based on paramaters supplied through the link URL. Rather than writing a long email response I wrote a little example app and this blog post. (If [...]

Tags: Rails, Routing, Ruby, web

How much duplication should we tolerate in tests?

As a developer I’m used to avoiding duplication in code. Avoiding duplication is even listed as one of the 4 rules of the TDD cycle: Start with a failing automated test You cant add new code without corresponding automated test You cant add tests if you have a red bar Eliminate duplication Yet quite often [...]

Tags: PatternsPractices, RSpec, Ruby, testing

Debugging in Ruby

Before I started doing Ruby I was doing mostly C#. This meant I did pretty much all my development in Visual Studio, giving me access to a very powerful debugger. Coming into the world of Ruby meant switching to Vim, which meant my editor started up in less than a second (instead of a few [...]

Tags: Editors, Rails, Ruby

[BUG] cross-thread violation on rb_gc()

I was recently involved in upgrading a project from Ruby 1.9.2 to 1.9.3. As part of this upgrade we also upgraded several of our gems (including Rails) to the latest versions. Everything went smoothly, but when I tried to run the latest version of the code on my laptop (MacBook Pro) I got the following [...]

Tags: Rails, Ruby

Comment Ruby code with Vim

I’ve recently started using Vim for Ruby/Rails development. As someone who is very new to Vim it has been a steep learning curve, but I’m really enjoying it – it has definitely become my editor of choice. One of the useful little tricks I figured out today is how to comment out a block of [...]

Tags: Ruby

Closures in Ruby

The complete title for this post is: Closures in Ruby make my head hurt. I’ve had a rough idea of how closures work (from my JavaScript experience), but I just watched An Introduction Blocks, Lambdas and Closures in Ruby and I’ve realized that I my knowledge is a mere drop in the ocean. I would [...]

Tags: Ruby

Alias class methods in Ruby

Yesterday I came across a problem where one possible solution was to alias a class method. I’ve blogged about aliasing methods before, but I didn’t know how to do this for class methods. Turns out, it’s pretty simple – the syntax is just a bit different. class Person def self.all %w{ Bob Steve } end [...]

Tags: Ruby

Using Zip in Ruby

Last week I blogged about the Enumerable module in Ruby and specifically mentioned the Enumerable#zip method. I didn’t think the zip method was particularly useful, but I have actually found a few extra features which are very nice. To refresh your memory, the zip method will combine the elements of two different arrays. names = [...]

Tags: Ruby

Presence of a substring in Ruby

I just watched the ‘Ruby Trick Shots’ video. This video basically shows a bunch of very useful methods, libraries and techniques you might be unaware of. If you’re a Ruby developer I would highly recommend it. One of the ‘tricks’ I found particularly interesting was checking for a substring. Let’s say we have the following [...]

Tags: Ruby

For vs Each in Ruby

One of the discussions I was involved in at RubyFuza revolved around the difference between for and each in Ruby. There is only a subtle difference around scoping, but I think it’s an important distinction because it reveals some important aspects of Ruby. The for loop is a syntax construct, similar to the if statement. [...]

Tags: Ruby