I think lots of folks have run into this problem of using error_messages_for to display errors of nested or subordinate objects. The current Rails method doesn't handle it well. In addition, there's the problem of not being able to specify the full message. So... I tackled this problem today and came up [...]
Category Archive for 'ruby'
I just implemented a statistics page for an application and found that I was using this pattern over and over again:
User.count(:conditions => ['created_at> ?', 30.days.ago])
Here's a simple extension I made to ActiveRecord to DRY it up:
module ActiveRecord
class Base
def self.count_since(time_ago)
count(:conditions => ['created_at> ?', time_ago])
end
end
end
Put [...]
Autotest CPU Fix
Posted in ruby on Jan 5th, 2008
Update 1/15/2008
Autotest and rspec both posted updates today. Now, the way to fix this issue is slightly different:
Autotest.add_hook :run do |autotest|
autotest.add_exception(/^\.\/vendor/)
autotest.add_exception(/\.svn/)
end
Thanks Ryan and David for the updates!
I've been noticing in my current project that running autotest was constantly consuming about 25-30% of my cpu and causing my macbook pro to run really [...]
Today we released a new Ruby Gem that makes integrating with Amazon E-Commerce Service (ECS) a snap. It's called acts_as_amazon_product and you can find it on RubyForge.
All that's necessary to integrate any of your existing models with Amazon is to add a require line to the top of your model file and then an [...]
Apache Log Quick Summary
Posted in ruby on May 10th, 2007
Sometimes I set up a quick site for a client and want to summarize hits without setting up awstats. So, I wrote a quick and dirty script to sum up the hits per day in Apache's access_log file.
Example:
$ cklog access_log
04-15-2007: 21
04-16-2007: 2134
04-17-2007: 304
04-18-2007: 6960
04-19-2007: 951
04-20-2007: 412
Here's the script:
require 'date'
daily = Hash.new
File.open(ARGV[0] || "access_log", "r") [...]
Ruby Web Crawler
Posted in ruby on Apr 19th, 2007
Here's a web crawler I wrote awhile back. It's pretty simple, but does the job. If you need something more, you might try rdig or Nutch.
You can run this as a stand-alone script and just pass in the URL to crawl as an argument.
require 'net/http'
require 'uri'
class SiteCrawler
def initialize(url)
@site_uri = URI.parse(url)
[...]
I've been working with soap4r in Ruby to access some Java web services which use AXIS 1.1. The particular api I'm accessing requires an initial authentication call which returns a token that must be passed in all subsequent SOAP headers. This is a pretty common scenario, but it took me awhile to get [...]
Geocoding webservice with Ruby and Perl
Posted in ruby on Jan 13th, 2007
A year or so ago I was trying out the Google Maps API. At the time, Google did not provide a means to geocode your own locations (although now they do), so I set out to create my own geocoder. There was a good overview on how to create your own database of [...]
Scott Nedderman is the founder of Netphase.com, a consulting practice that specializes in building web applications for Internet startups. He is also a vocalist, plays guitar and penny whistle, occasionally performs in musicals, enjoys camping and is a homeschooling father of 6.



