Read my latest article: 8 things I look for in a Ruby on Rails app (posted Thu, 06 Jul 2017 17:59:00 GMT) in a hour...

Posted by Mon, 14 Mar 2005 16:27:51 GMT

Ok, I will admit it. I spent much longer than a hour on this. I spent about a hour coding, testing and adding a few CSS tags to the few pages. I spent a few hours trying to figure out why my RewriteRule was not working.

At about 10pm on Sunday evening, I had an idea… hey, I’ll spend the rest of the night on a simple Rails project… and after being sent a link for a tinyurl, I thought, Hey, I’ll just create So, I checked, the domain was available and I will now own it until this time next year.

The system thus far comprises of 1 database table, 2 controllers and 1 model that were added to the default rails install. (not including the Rails templates for new.rhtml and show.rhtml).

The random character string function that I used is here: This allos me to create some random alpha-numeric string like ur029
class Rubyurl < ActiveRecord::Base

  def self.gen_random(size=5)
    chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890" 
    short_url = "" 
    size.times do
      pos = rand(chars.length)
      short_url += chars[pos..pos]

So, with the standard usage of scaffold I was able to create a random string prior to saving my form:
  def create
    @rubyurl =['rubyurl'])
    @rubyurl['short_url'] = Rubyurl.gen_random(5)
      flash['notice'] = 'Rubyurl was successfully created.'
      redirect_to :action => 'show', :id =>
      render_action 'new'

The last part in the ruby code was to make it actually redirect to another location:

class GoController < ApplicationController

  scaffold :rubyurl

  def go

  def index
    @url = Rubyurl.find_first(["short_url = ?", @params["id"]])
    if @url['website_url']
      redirect_to @url['website_url']


... so just over 2 1/2 hours later (mainly due to a problem with the RewriteRule..), I am now happy to announce the alpha release of RubyURL.

I’ll write more about my findings when I wake up.. off to bed.

Rails Login with MD5

Posted by Mon, 14 Mar 2005 03:14:03 GMT

I am working on migrating an existing system that utilizes MD5 rather than SHA1 for password encryption so I needed to make a few adjustments to the login process.

I had issued the following command which created some objects to work with.
./script/generate login User

My existing system also uses the email address as the login username, so I modified the the file ./app/models/user.rb:

I changed this:
  def self.sha1(pass)
  def self.md5(pass)

Then I went and changed instances of sha1 in user.rb to md5.

The next step was to modify the field that authentication was checking the database with.

I changed this:
  def self.authenticate(login, pass)
    find_first(["login = ? AND password = ?", login, sha1(pass)])
to this:
  def self.authenticate(login, pass)
    find_first(["email = ? AND password = ?", login, md5(pass)])

The last step was to modify the table that the system looks in for the users who can login to the system. Still in user.rb, I added this to the top of the User class.

class User < ActiveRecord::Base

def self.table_name() "employees" end


Typo on PostgreSQL

Posted by Sun, 13 Mar 2005 21:02:00 GMT

As Typo only supported SQLite and MySQL so far, I submitted a PostgreSQL schema file for the project. This new blog is running on PostgreSQL 8.0 and Rails!

I am going to use this blog to follow my Rails-related projects..and post tips and tricks!


UPDATE Links have been updated as the original typo svn/trac is gone.

Older posts: 1 ... 42 43 44