Monthly Archives: July 2006

Rails Model Validators

When developing a Ruby on Rails web application it is a good idea to use ActiveRecord validators to insure the state of a record before posting it to the database. To flush out this example I present the following model:

class User < ActiveRecord::Base
validates_uniqueness_of :username
validates_presence_of :username, :password, :email
validates_size_of :username, [...]

Posted in Ruby, TechKnow | 10 Comments

Ruby Time Formatting

The Time class in Ruby has a powerful formating function which can help you represent the time in a variety of ways. The strftime function is modeled after C’s printf. Here are some usages examples:

t = Time.now
t.strftime(”%m/%d/%Y %H:%M:%S”) # 07/24/2006 09:09:03

t.strtime(”%A”) # Monday
t.strftime(”%B”) # July

You can use the lower case a and b [...]

Posted in Ruby, TechKnow | Leave a comment

CSS Hackary

A friend of mine recently asked me what was my most used CSS hack. The first thing I said was that I am not a web designer, I just play one on TV. I have found that everybody knows or can easily look up how to apply a border, text alignment, background image, [...]

Posted in CSS, TechKnow | Leave a comment

Ruby Symbols

If you are new to the Ruby programming language and only just recently started programming in Ruby via Rails you must be wondering what the hell are those thingies used to name actions in the link_to ActionView helper function. Here is an an example of what I mean:

<%= link_to ‘link’, :action => ‘myaction’ [...]

Posted in Ruby, TechKnow | 3 Comments

Ruby Language Goodies For Java Developers

If you are new to the Ruby programing language you might not be familiar with some of the short semantic sugar or language goodies that Ruby provides. I think that for most of the hard core Java developers the code samples that will be provided here will be novel but Perl hackers will not [...]

Posted in Java, Ruby, TechKnow | Leave a comment

Acts As Taggable Conditions Hack

I’ve been happily using the Ruby on Rails acts_as_taggable plugin for some time now. But recently I had a situation that where I had to hack the plugin. The taggable plugin provides a find_tagged_with method that is used to find all records for a given model with a certain tag. Here is [...]

Posted in Ruby, TechKnow | Leave a comment