Eric Goodwin

archive

Reordering your Objects
06/01/25

I thought I’d share something that I learnt on the rubylist today to do with reordering your results after a query to your database.

1
2
3
4
5
6
7
#controller:
@categories = @site.categories

#view:
<% for category in @categories.sort { |a,b| a.name <=> b.name } %>

<% for category in @categories.sort { |a,b| a.rank <=> b.rank } %>

This will let you reorder you objects by name or rank or whatever other attribute you want to order by.

Thanks to Tom Mornini for sharing this tidbit on the mailing group today.

If you aren’t part of the rails mailing list I’d suggest subscribing. There is alot of mail to wade through, but most of it is pretty darn good and helpful.

0 comments

Rails, Databases and Dates
06/01/24

On one of the projects that I am working on at the moment I am doing alot of work with dates and events. I’ve had to write quite a few find_by_sql for some of my more complicated queries and a nice little rails date helper has come in handy.

#Time
1.year.ago.to_s(:db) 
#=> '2005-01-24 15:29:24'
Time.now.last_month.to_s(:db) 
#=> '2005-12-24 15:29:24'

#Time Range
(Time.now..Time.utc(2006, 12, 24, 09, 00)).to_s(:db)
#=>'BETWEEN 2005-01-24 15:29:24' AND '2006-12-24 09:00:00'", 

#Date
Date.today.to_s(:db) 
#=> '2006-01-24'
5.days.from_now.to_date.to_s(:db) 
#=> '2006-01-29'

#Date Range
(Date.today..1.year.ago.to_date).to_s(:db) 
#=> "BETWEEN '2006-01-24' AND '2005-01-24'"
Update: This one doesn’t have much to do with the database at all, but it’s still a very handy function
#Get last day of March 2006
Time.days_in_month 3, 2006 #=> 31

1 comment

Lighttpd for Windows
06/01/24

I develop and test my rails apps on a windows box and until now, I’ve been using Webbrick as my webserver. Now Lighttpd has finally been released for windows. You can find it here. I have yet to install it but once I do I’ll update this post with my thoughts.

Update:I’ve finished installing it on one of my machines and it seems to be running quite smoothly. Webbrick often crashed or hung when under stress, but so far, Lighttpd seems to be hanging in there and serving pages nicely.

Update:I now have lighttpd running multiple rails apps on a single box and everything seems to be working quite well.

Update: Check out Lighttpd Virtual Hosts with SCGI on Windows to see how to get multiple virtual hosts running.

7 comments

I love EdgeRails
06/01/20

It just had to be said. With one line of code I’m up to date with the latest code. This latest update includes Sam Stephenson’s render :update allowing me to use rjs templates inline. No more two line .rjs files.
Go on, you know you want to.


rake freeze_edge

0 comments

Great HttpRequest Debug Tool for Firefox
06/01/15

Julien Couvreur just released the latest version (1.2) of his XmlHttpRequest Debugging greasemonkey script. I’ve been using this greasemonkey script for sometime now and have found it to be such a great help when trying to debug any ajax work that I am doing. You should check it out. My favorite greasemonkey script by far.

1 comment

Canada On Rails
06/01/15

I’ve been thinking abouting heading over to Van for the Ruby on Rails conference this April for a while and then today I finally forked out the $175. It should be a blast. You can see the speaker list on the Canada on Rails website. Drop me a line if you are heading to it to and maybe we can meet up.

0 comments

Living Life On The Edge
05/12/31

Want to live life on the edge … of rails. There is a great entry on the wiki that explains how to do just that. It’s as easy as one line of code if you have subversion installed on your computer.

0 comments

About

Eric Goodwin is a web developer living in Victoria BC, Canada. You can contact him at eric@ericgoodwin.com

Open Source

Projects

Elsewhere

Archives