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

Rails Wiki backup

Posted by Thu, 22 Sep 2005 13:53:00 GMT

Since the Rails Wiki is currently down, I took the backup and stuck it online. (perhaps this could become a read-only html mirror of the site)


Please note that backup is not back up ;-)

This will be managed by the Portland Ruby Brigade


DHH says that the i2 will be up and running later today! :-)

Rails meets FuseFS

Posted by Wed, 21 Sep 2005 19:28:00 GMT

_why has posted an entry on his blog which shows how to use the Ruby FuseFS library to… mount Active Record.

railsmnt]$ cat contact_type/1
--- !ruby/object:ContactType
  name: Client
  id: "1" 

 railsmnt]$ for i in `ls`; do echo $i; done

Umm… I am… I dunno… (wow)

I’ve used FuseFS for mounting SSH… but found myself using SSHFS as a better alternative.

But… to mount Rails? This could get interesting.


A screenshot while browsing the directory with Konqueror…and opening the record with Kedit.

UPDATE #2 If you’re hosting at PLANET ARGON, you can try this out with your account. Both, FUSE and Ruby-FuseFS are installed on all the servers.

Ruby 1.8.3 released, but Rails not liking it

Posted by Wed, 21 Sep 2005 00:23:00 GMT

Ruby 1.8.3 was released this evening. Yay!

Problem is?

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/clean_logger.rb:13:in `remove_const': constant Logger::Format not defined (NameError)

Every Rails application that I tried with it died. So the solution?

cd ../ruby-1.8.2
./configure && make && make install

No 1.8.3 for PLANET ARGON yet.

DHH interviewed by O'Reilly

Posted by Wed, 31 Aug 2005 10:46:00 GMT

I just finished reading a very nice interview of David by O’Reilly

You can read it here.

While reading it, I recalled a brief conversation that I had the other day, when someone said that they didn’t like Rails because, “it assumes things” which translated to the fact that they didn’t like that it had a uniform directory structure, pre-defined naming conventions, etc.

After spending this whole year, teaching myself Rails, reading the documentation pages… (probably at the API site a few hours a day), this concerned me. A lot of people are quickly turned off by the fact that Rails has opinions. But, let’s think about this for a moment. Rails has opinions built-in that help speed up the development process when you accept those opinions. If you don’t, you don’t have to pspend any more time than you did prior to using Rails. So, their argument is, “why bother with Rails?”

At first, the answer isn’t so obvious…. but if you consider all the opinions that Rails expresses, do you honestly feel that every one of them is wrong? If so, Rails is probably not for you. If you find a good portion of them to be quality opinions, then… Rails just might be your cup of tea afterall.

Pluralization make you feel weird? Turn it off. (one line of code will do this for your whole application.

Wait, you want to use category_id as your primary key?

class Category < ActiveRecord::Base
  set_primary_key "category_id"

Yes, I know… it’s tough. ;-)

Another thing that I am wondering now… what is the conductor?

My guess? Some added bonus for Rails that allows you to run a Rails application off of one or many servers… now that would be nice. That’s my guess though… what is yours?

When TSearch2 Met AJAX

Posted by Mon, 22 Aug 2005 01:48:00 GMT

Last night, a local PDX.rb-ist, asked about full text searching in PostgreSQL. I pointed him to TSearch2, which is a nice little addon to handle full text searching with indexing, ranking, highlighting, etc. To my knowledge, it’s the closest to a google-like search that you can get with PostgreSQL. Some people in #postgresql (, said that you can build custom functions that will allow you to quote content, and do other fun stuff within your search string. We can discuss that another time.

After thinking it over, I thought, “why not put ajax on top of a full text search and see what it can do?”

The first question, where was I going to get a bunch of content that I could search through and have it be somewhat meaningful for the public, if I decide to put it up as a demo page. The RubyOnRails mailing list came to mind, so after seeing that I couldn’t download the full archive from the rails mailman page (at least not that I could tell), I decided that I would just import my Maildir for that mailing list.

This added another initial step. What would be a good way to import the 13,000~ emails that I had in the folder?

I knew that worst case, I could find a module on CPAN and build a perl script to import it… since I didn’t see anything in the standard ruby library. Then I found TMail. Someone said that they think ActionMailer uses TMail as well.

The resulting quick and dirty script became:

#!/usr/bin/env ruby

require 'tmail'
require 'rubygems'
require 'postgres'
require 'dbi'

conn = DBI.connect("DBI:Pg:database=rails_mailinglist;host=localhost;port=5403", "username", "password" )

MAILBOX = ".MailingLists.Ruby.RubyOnRails"

sql = "INSERT INTO archives (sender, recipient, subject, body) VALUES (?,?,?,?)"

@sth = conn.prepare(sql)

box =

box.each do |port|
        mail =
        p mail.subject
        @sth.execute(mail.from,, mail.subject, mail.body)


Not rocket science. :-)

Okay, so I let that start running through the mailing list emails that I have, and opened up another tab in iTerm and typed our friend, rails archives followed by cd archives. The next step was to modify the config/database.yml file.

(you all know how to do that, right?)

Okay, you should still be with me…so far.

After I got my database settings in place, I ran ./script/generate scaffold Archive and watched it created my new filles to play with.

./script/server and I am looking at the first several emails that are in my RubyOnRails mailing list folder. I notice that the first one is the confirmation email from the day that I signed up on the mailing list. Mon, 24 Jan 2005 16:00:14 +0000 (GMT) . So, I delete that email and the ‘welcome to..’ one so that no one sees my mailman password/confirm info. ;-)


So, Rails has no problem with the data. So, I then head over to the Tsearch2 site and look for some installation information. I walked through this walkthrough

Database Structure

For this example, I kept it pretty simple for the database structure. I believe the create script was:

CREATE TABLE archives (
  sender VARCHAR(255),
  recipient VARCHAR(255),
  subject VARCHAR(255),
  body TEXT

The rest was basically following through with those steps and building the triggers and functions around the subject and body fields in the table.

To use the tsearch2 functionality, I used find_by_sql rather than using just find.

@archives = Archive.find_by_sql("SELECT id, headline(body,q) as headline, body, rank(idxfti,q) as rank, sender, subject  FROM archives, to_tsquery('#{@str}') AS q WHERE idxfti @@ q ORDER BY rank(idxfti,q) DESC LIMIT 100") 

The @str variable is a value that I build based on the string(s) that the user is typing in the search field. Tsearch2 requires that you sepeare each string with a pipe (|). So, I put in a few checks on the string that was being passed to my method in my controller by AJAX. (I’ll let you take the time to figure out how to get AJAX in Rails working and watching a text field… it’s not hard to find info on google. ) :-)

The end result?

I will warn you that this does’t work in all browsers, some IE people said they had issues… and I spent enough time tinkering with it to just settle with this for now. :-)

I present… fulltext searching with PostgreSQL on Rails.

There are approx 13,000 emails in the system, so I put a limit on the number of responses that show up to 100.

My Thoughts

Well, it was an interesting concept. I’m not a big fan of livesearching, it doesn’t really seem to buy us much when working with this sort of data. I do find live auto-completion to be quite useful though. It’s not practical to have AJAX peg the database every second as I type for new content and it’s obvious that a database with that much content is not going to respond as snappy as you would hope. However, I decided to compare the speed to searching in Thunderbird and Evolution. From my sophesticated benchmarking suite (my imaginary stop watch)...

AJAX won!

okay, I should be fair and say, Tsearch2 won as it is doing all the heavy lifting.


Are you a console master?

Posted by Fri, 19 Aug 2005 02:06:00 GMT

1 comment Latest by Lance Wed, 02 Aug 2006 10:58:30 GMT

I have a few questions.

1.) Do you know what ./script/console does?

2.) If not, why not?

3.) If so, do you have any fun tips and tricks to share with the masses?

It occured to me earlier that many people, who might have came from the PHP camp, may have never really tested their object-oriented code from some sort of interactive program. (irb) If you are coming from the Python, Java, etc worlds, interactive testing isn’t anything new. Rails is nice enough to bundle a console script right within it!

I meet people online who have never even tried to run it. There are not many tutorials on the wiki that show console… and in my opinion, its one of the coolest things about Ruby and Rails. (but, I come from the php world…)

So, if you aren’t using it… why not? got a moment? try this from the root path of your Rails application.

It start up okay? If so, what is the name of one of your models? Let’s say that I have a model structure like:
class Customer < ActiveRecord::Base
  has_many :orders, :dependent => true

class Order < ActiveRecord::Base
  belongs_to :customer
From console, you can access your models and do all sorts of fun things.
>> y = Customer.find(16)
=> #<Customer:0x2743ea4 @attributes={"name"=>"Robby", "id"=>"16"}>
>> y.orders
=> [#<Order:0x27416b8 @attributes={"id"=>"18", "amount"=>"12.00", "customer_id"=>"16"}>, #<Order:0x274167c @attributes={"id"=>"19", "amount"=>"12.50", "customer_id"=>"16"}>] 

Pretty neat, huh?

>> o = Order.find(18)
=> #<Order:0x273da68 @attributes={"id"=>"18", "amount"=>"12.00", "customer_id"=>"16"}>
=> "Robby" 

If you are remotely a console wizard, please share some tips and tricks for those who are not sure what to do with it. I personally find myself in console all the time that I am working with Rails, testing stuff out with my models, before I move any of the code to my application.

It sure beats, hitting refresh in your browser all day. :-)

Older posts: 1 ... 24 25 26 27