I always have a problem parsing Rails‘ named routes in my head. It usually takes me a lot of time and effort to decide which controller action or view file is responsible for given path. Of course, it’s easy to tell when you look at:
that you probably should go to
users_controller.rb and find
edit action and
views/users/edit.html.haml is the right view file. But when nested routes, prefixes and non-RESTful actions all come to play, you might end up with a monster like:
Don’t laugh, this is real. So, what’s going on here? What is the action name? Are those “employer” things prefixes or nested routes? Where do I find the view? To answer all these questions, the Rails Routes TextMate bundle was born.
Here’s a quick tip for enhancing your test writing productivity: use
assert‘s last parameter, the message. Virtually all
assert_... methods accept it. You may have noticed in the docs that the last parameter is always
message = nil or
message = "". Too bad the docs don’t give examples on how to use this message. So, let me fix that.
Shoulda gem is great not only because it provides you with a very clean and natural way of organizing tests with
should building blocks, but it also comes with quite a large set of predefined macros that mirror Rails’ validations, relations etc. What’s even better — it’s very easy to create your own macros to further speed up test writing. Modern versions of Shoulda gem allow to do it in a clean and modular way. That’s great news if you are serious about TDD because for every substantial codebase you will end up with even bigger pile of testing code, so any tool helping in encapsulating common test logic or patterns is priceless.
This article is a tutorial on writing custom Shoulda macros: from very simple to quite complex.
This is my list of TextMate‘s keyboard shortcuts that are very useful for Ruby and Rails developers, but are not used as widely as they should (according to my very scientific observation on a very representative sample, i.e. my colleagues). I skipped all the obvious ones (like “open file”, “save file”, “go to next window”, “close window” etc.) that most people use anyway. My list includes shortcuts that are very useful but sometimes might be hard to grasp at first or might require a little explanation.
I18n layer, introduced in Rails 2.2, is said to be “the simplest thing that ever could work”. Too bad they didn’t go for “the simplest thing that could be practical to use”. These two can be very far apart. I have a hard time imagining a real-world app using only bare Rails’ I18n engine.
Another unpleasant thing is that Rails 2.2 broke GetText compatibility, which prevents many projects from migrating to Rails 2.2 or later versions.
Well, not anymore. Thanks to clever guys Masao Mutoh and Michael Grosser, it’s finally possible to get Rails 2.2 running with GetText. Read on for details.
Small tip: when you happen to be running Rails in a console that doesn’t understand ANSI codes (those pesky
←[0;1m that clutter your display), like for example Windows’
cmd, you can turn them off with:
if RUBY_PLATFORM =~ /mswin32/
ActiveRecord::Base.colorize_logging = false
Put this in
config/environments/development.rb and restart
Took me a while to find it, so I thought I’d post it for posterity :)