Filtering with named scopes (encore)
In my previous post, I talked about making filters using named scopes. To summorize: I like the method of using a named_scope and delegating to specified filters. This way, you can structure your...
View ArticleSilencing Passenger
When using Rails 2.3 and Passenger, you can do yourself a favor by adding this line to config/silencers/backtrace_silencer.rb Rails.backtrace_cleaner.add_silencer { |line| line =~ /^\s*passenger/ }...
View ArticlePlugin release: Root table
Yes, I've written another plugin for Rails. It's about so called root tables. It seem to be making them often. I want a list with options to choose from and some easy way to manage that list, which is...
View ArticleConfiguring Autotest
I have a big test suite in the current Rails application I'm working on. I have 2340 examples in RSpec, taking over 2 minutes to run. This is an absolute pain to run. Luckily there is autotest (or...
View ArticlePrawn and controller tests
There is a real annoying gotcha in using controller tests to test an action that renders a pdf with Prawn. You'll get a NoMethodException on "nil.downcase". The troubling part is that it totally puts...
View ArticleCucumber 0.5 and my little commit
The strangest thing happened to me this week. I was working on a little side project at work. It seemed like a nice time to try out some new gems (Bundler and Devise: love it! InheritedResources, not...
View ArticleBasic Named Scopes
Cal it tiny, I don't care. I've made a gem named BasicNamedScopes. Basic Usage I was fed up with writing: Post.all(:conditions => { :published => true }, :select => :title, :include =>...
View Articlehttp_accept_language released as a gem
I released an old Rails plugin as gem today. Slowly but surely, all my plugins will be converted to gems. This time it's an old one: http_accept_language Splits the http-header into languages specified...
View Article3 times ActiveSupport 3
Rails 3 is coming. All the big changes are spoken of elsewhere, so I'm going to mention some small changes. Here are 3 random new methods added to ActiveSupport: presence First up is Object#presence...
View ArticleGoing crazy with to_proc
You all know Symbol#to_proc, right? It allows you to write this: # Without Symbol#to_proc [1, 2, 3].map { |it| it.to_s } [3, 4, 5].inject { |memo, it| memo * it } # With Symbol#to_proc [1, 2,...
View ArticleMonkey Patch of the Month: group_by
A while back, I talked about new additions to ActiveSupport. And now, I have a confession to make: I like monkey patches! At least, as long as they're short and self-explanatory. I got a few of them...
View ArticleOdd Ruby Methods
I recently encountered some methods I didn't know about. ~ The tilde method (~) is used by Sequel and you can use it like this: class Post def ~ 11 end end post = Post.new ~post # => 11 That's...
View ArticleMonkey Patch of the Month: attr_initializer
So, about one month ago, I promised to share some useful monkey patches every month. Here is the second one. Your own monkey patches are still more than welcome! I often find myself writing code like...
View ArticleQu'est-ce que c'est Rubyesque?
This is a translation of the post I originally wrote down in Dutch for my company. I recently gave a presentation at my company Finalist IT Group about the philosophy behind Ruby. Code written with...
View ArticleViewTranslator, a dynamic dispatcher
I'm a sucker for syntax. So once again, here's a small experiment. It might not be the most useful snippet out there, but maybe it inspires you to do something awesome. The 'Dynamic Dispatcher' is a...
View ArticleConway's Game of Life; or: Writing Perl in Ruby
We had a programming exercise this week at work. We were set out to write Conway's Game of Life, using pair programming and TDD. It was a fun and educational evening. I even did some Scala. Programmers...
View ArticleHelpers Are Code Too!
I think I've talked about this before, and there has been a Railscasts episode about it too, but I want to touch on it again. I know we're supposed to keep views simple, but that doesn't mean that...
View ArticleCheating Performance With A Little Javascript
This little trick works with most websites with a menubar. When you have a menu that changes color pending on which page you are, you can cheat a bit on the perceived performance of loading pages. And...
View ArticleAbout structs
Recently I talked about a monkey patch called attr_initializer, allowing you to write code like this: class FooBar attr_initializer :foo, :bar def to_s "your #{foo} is #{bar}" end end FooBar.new('foo',...
View ArticleUsing Sass with jQuery UI
Want to build a quick website or backend? Want to make it look good, but without adding too much effort in it? Then this recipe is for you! The jQuery UI framework contains some nice styles and some...
View Article