Politics, Programming and Possibilities
8 Oct
When Dave and I first developed FamilyAnywhere.com, we built it with the intent that some day we would hire a Real Designer to make it look like a professional site. For anyone who cares to make a visit right now, it definitely still looks like a couple of coders put it together—and that would be an accurate observation.
So my question to put to out there today is, are you a website designer or graphics guru looking for a side job? We’d love to talk to you. Drop me (Duane) a line at duane.johnson@gmail.com.
28 Sep
Update: The repository has moved slightly, since the Rails.tmbundle got renamed to “Ruby on Rails.tmbundle”. The URL looks like this (no newlines):
http://macromates.com/
svn/Bundles/trunk/Bundles/Ruby on Rails.tmbundle/
Support/plugins/footnotes
This release of the TextMate Footnotes plugin has several new and helpful features:
I’ve also moved the project in to the TextMate Repository, so you can either get it with TextMate, or use subversion to get it directly here:
svn --username anon --password anon co http://macromates.com/
svn/Bundles/trunk/Bundles/Rails.tmbundle/
Support/plugins/footnotes footnotes
(Note: the subversion checkout command above should all be on one line.)
23 Sep
ActiveRecord gives a lot of flexibility with its 16 callbacks. I’ve never needed anything more granular than that flexibilty until today.
In trying to automate the process of saving files on Amazon S3, I needed a callback that would be triggered after the creation of my “Photo” record, but before the creation of several associated objects. (These ActiveRecord objects were being held in memory via the association “build” method, and thus had not yet been inserted in to the database.)
Delving deep in to ActiveRecord to figure out how those build-associated objects were being automatically inserted in to the database when calling “save” on my Photo object, I found out it’s a lot easier than it might seem.
Just define your “after_create” callback before the call to “has_many” in your class. For example:
class Photo < ActiveRecord::Base
# This callback must be defined before "has_many :versions" so
# that it gets called *after* the Photo is created, but *before*
# the versions are inserted in to the DB.
after_create :send_id_to_versions
has_many :versions
def send_id_to_versions
...
end
end
If you switch the order of the after_create and the has_many above, the “Version” objects will be inserted to your database before the call to “send_id_to_versions”.
Hope that saved you an hour or two! ![]()
20 Sep
UPDATE: In the comments, Kent has provided a complete solution to this problem:
hash = Hash.new(&(p=lambda{|h,k| h[k] = Hash.new(&p)}))
I would love to see this integrated in to the Hash class at some point, but if not, we can (with Ruby’s kind acceptance) do it ourselves:
class Hash
def self.arbitrary_depth
Hash.new(&(p=lambda{|h,k| h[k] = Hash.new(&p)}))
end
end
Thus,
hash = Hash.arbitrary_depth
h = Hash.new
h[:one][:two] = "uh-oh!"
# NoMethodError: undefined method `[]=' for nil:NilClass
The solution? Pass in a proc that will tell Hash to create a second hash by default for each key that is not found:
h = Hash.new { |h,v| h[v]= Hash.new }
h[:one][:two] = "uh-oh!"
# => "uh-oh!"
h
# => {:one=>{:two=>"uh-oh!"}}
Much better. But that’s only two-deep. What about n-deep? The solution I found isn’t fully “arbitrary” on demand, but it should work for most cases:
class ArbitraryDepthHash
def self.arbitrary_depth_proc(depth = 1)
proc { |h,v| h[v] = Hash.new(&arbitrary_depth_proc(depth-1)) }
end
def self.[](depth)
Hash.new(&arbitrary_depth_proc(depth))
end
end
h = ArbitraryDepthHash[5]
h[:one][:two][:three][:four][:five] = "wow!"
# => "wow!"
h
# => {:one=>{:two=>{:three=>{:four=>{:five=>"wow!"}}}}}
1 Sep
Gerardo Lisboa recently enquired about the ColumnComments plugin, noting that comments can not be added to columns during the creating of a table (usually the most useful time to add comments!) He is, of course, absolutely right–the comments option did not work in version 1.1. In response, I wrapped up a zip file of my current implementation and sent him the update.
For anyone else who is using ColumnComments, I recommend using this upgrade (MySQL only).
Download the zip file here, and then unzip it in to your Rails app’s vendor/plugins directory.
4 Aug
I’ve begun experimenting with the new Edge Rails code that includes built-in support for REST. (The code that was once in the simply_restful plugin is now a part of Edge Rails.) With the capability to generate multiple types of output per action, it has become more and more useful to test actions on the command-line using cURL. Here are some useful cURL parameters I’ve used:
curl -X DELETE http://localhost:3000/books/1
curl -d "book[title]=Test" -d "book[copyright]=1998" http://localhost:3000/books
curl -H "Accept: text/xml" http://localhost:3000/books/sections/1
Putting it all together, here’s a cURL command that updates the title of a Book object using the PUT action and expects an xml response:
curl -H "Accept: text/xml" -X PUT -d "book[title]=Testing Again" http://localhost:3000/books/1
31 Jul
Benjamin Curtis has been seeding his Rails Plugins Directory project by taking announcements on the Rails list and documenting them on his website. He added tags a while back, and the list of plugins is now very impressive!
Take a look yourself and see if you like it.
28 Jul
It’s been almost two months since my last post, and that makes it about time I wrote again. I’ve been silent on this blog primarily for three reasons:
I will post about each of these items separately.
2 Jun
This seems to have been around for a while, but I missed the announcement some months ago. It’s a cool little in-browser documentation package that provides Ruby on Rails docs in Firefox. It also has some CSS, PHP and HTML documentation packages that you can download.
It’s called DevBoi (where’d that name come from?) and it’s available from Martin Cohen.
24 May
I just created a “blog” at inquiry.newsvine.com where we put our FamilyAnywhere.com press release / announcement. Check it out if you’re interested in how Family Anywhere got started.subsidized stafford loan 2008-2009apyday 2000 loanloan bank rajhi malaysia al personalloan amerization oftexas in 500 fiko loans carequlity 530 home fico loansloans insurers maplight ab orgfico score 500 for commercialloans financing Map