Use different code for Rails 2 and Rails 3
When writing a piece of reusable code, you sometimes need to have separate code for Rails 2 and Rails 3. You can distinguish between Rails versions like this:
if Rails.version < '3' # mind the quotes
# Rails 2 code goes here
else
# Rails 3+ code goes here
end
Related cards:
How to view Image Metadata on the Linux Command Line with ImageMagick
ImageMagick has a command line tool called identify
which can read image metadata:
>identify -verbose DSC00136.JPG
Image: DSC00136.JPG
Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 5472x3648+...
Upgrading Rails 2 from 2.3.8 through 2.3.18 to Rails LTS
This card shows how to upgrade a Rails 2 application from Rails 2.3.8 through every single patch level up to 2.3.18, and then, hopefully, Rails LTS.
2.3.8 to 2.3.9
This release has [many minor changes and fi...
DNS debug tools
There are several tools for DNS debugging which offer you more or less information. Most of the time the more simple ones, like host
oder nslookup
will be sufficient.
host
simple DNS lookup utility.
>host heise.de
heise.de has addr...
Video transcoding: Web and native playback overview (April 2020)
Intro
Embedding videos on a website is very easy, add a <video>
tag to your source code and it just works. Most of the time.
The thing is: Both the **operating system and Browser of your client must support the container ...
Security issues with hash conditions in Rails 2 and Rails 3
Find conditions for scopes can be given either as an array (:conditions => ['state = ?', 'draft']
) or a hash (:conditions => { 'state' => 'draft' }
). The later is nicer to read, but has horrible security implications in some versions of Ru...
Customize your Bash prompt
The shell variable PS1
holds your bash prompt. You might want to change it to serve your needs best. Here is how to:
General
- non-printing escape sequences in your prompt have to be inclosed in
\[\e[
and\]
so your shell can...
Upgrading Cucumber and Capybara to the latest versions available for Rails 2
Specify these gem versions in your Gemfile:
gem 'cucumber', '~> 1.3.0'
gem 'cucumber-rails', '= 0.3.2' # max version for Rails 2
gem 'capybara', '< 2' # capybara 2+ requires Rails 3
gem 'mime-types', '< 2' # dependeny of capybara
...
Why you can't use timezone codes like "PST" or "BST" for Time objects
Rails' ActiveSupport::TimeWithZone
objects have both a timezone code and offset, e.g. Thu, 28 Mar 2019 16:00:00 CET +01:00
. Ruby's stdlib TZInfo
also has time zones, but with different identifiers.
Unfortunately, not all timezone codes can b...
Lightning Talk: Coverage based Test Case Prioritization in Ruby on Rails
For my computer science bachelor's thesis I programmed and evaluated a CLI Test Case Prioritization (TCP) tool for makandra. It has been written as a Ruby Gem and was tested and evaluated against one Ruby on Rails project....
Nested controller routes (Rails 2 and 3)
In order to keep the controllers directory tidy, we recently started to namespace controllers. With the :controller
option you can tell Rails which controller to use for a path or resource. For nested resources, Rails will determine the view pat...