Posts Tagged by Ruby on Rails

Ruby and Rails – Time, Date, DateTime, TZInfo

From a discussion (Ruby – The Non-awesome parts) on the RORO email list – the differences between Time, Date, DateTime and TZInfo:

>> Time vs Date vs DateTime vs TZInfo (vs ActiveSupport::TimeZone). Which
>> do I use and when?

Time is a timestamp and can represent a moment in time no matter where
it occurred in the world, agnostic of timezone. Think UNIX timestamps.
Date is a thing on a calendar that might mean a different moment in
time to different people depending on their timezone. Think of Date
for things like recording your birthday. DateTime subclasses Date and
adds hour, minute, second and timezone information to a Date so it
becomes a lot like Time, but that makes me unsure when to use DateTime
and when to use Time, to be honest.

Time has timezone capabilities built in. TZInfo has a different set of
timezone capabilities and operates with Time objects, but seems to
ignore their built-in timezone settings. I’m still not sure why.

Installing Aptana + RadRails on Ubuntu Jaunty

I’ve always used vim as my main editor, but I thought I’d try RadRails since so many Rails people rave about it. Installing it on Ubuntu Jaunty is a bit non-obvious:

  • sudo aptitude install openjdk-6-jre (or your preferred jre)
  • download and unpack aptana zip to ~/.aptana
  • download and unpack xulrunner to ~/.xulrunner
  • create a script like ~/bin/aptana:
#!/bin/bash
MOZILLA_FIVE_HOME=~/.xulrunner
if [ $LD_LIBRARY_PATH ]; then
    LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME:$LD_LIBRARY_PATH
else
    LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME
fi
export MOZILLA_FIVE_HOME LD_LIBRARY_PATH
~/.aptana/AptanaStudio -vm /usr/lib/jvm/java-6-openjdk/bin

[ubuntu] Installing Aptana on Jaunty – Ubuntu Forums

ruby gem server

I’m back to Rails development after a few months doing other things. Note to brain: the ruby gem server is now started using gem server & rather than gem_server &, like it used to be… </frustration>

Offline rdoc gem documentation in Ruby

Ruby on Rails select_tag default value

When using the Rails helper select_tag, the selected value (ie highlighted value) is a parameter to options_for_select, not select_tag. Eg:

Number of Rows: <%= select_tag(:numrows, options_for_select(%w{10 20 50 100 200 500}, session[:numrows])) %>

(much head-banging-against-wall went into working this out…)

Ruby on Rails – Foreign Key Constraints in MySQL

As an ex-DBA, one of the things that annoys me about Rails is that migrations don’t have a way of setting up referential integrity (I’m still using Rails 1.2.3, so this may have changed). But apart from that, I lurv Rails :-)

Here’s some code I wrote to for adding and removing foreign key constraints on MySQL (using InnoDB, of course). There’s other code out there to do the same thing, but they didn’t do what I wanted, or required installing a plugin. (more…)