Tweaks to scaffolding for adding “child” rows

30
Aug/07
0

There are times when you need to use a bit of Rails scaffolding to get up and running and for various reasons you don’t want to resort to ActiveScaffold or some other medium-weight strategy. All you want to do is provide the user a means to see a “master” row, and then allow for adding a row to a dependent (”child”) table. Here we’re talking about “the simplest thing that could possibly work.” This example is for Rails 1.2.3.

Typically the recipe is going to be like so:

Add your scaffolds:

script generator/scaffold master Admin::Master
script generator/scaffold child Admin::Child

Edit your migrations to get your data model where you want it.

In master/show.rhtml, add

<%= link_to 'Add child', :controller => Admin::Child,
  :action => 'new', :id => @master.id %> <br/><br/>

In child/_form.rhtml, add

<%= hidden_field 'child', 'master_id', :value => params[:id] %>

That’s essentially it. Now after adding a Master record, you click the scaffold’s “show” link, and that view will give link to add a Child record with its foreign key set to the value of the Master for which you are adding the Child.

As soon as it gets complicated, though, go use ActiveScaffold.

Filed under: Rails, Technology

Ruby HTML parser with event callbacks?

29
Aug/07
0

Yeesh. I have some fairly icky HTML that would be a trivial parsing job with an HTML parser that provides callbacks (a la SAX) and some lenient error handling. Too bad I can’t plug an error handler into REXML.

Nasty. Maybe I will do this in JRuby and a Java SAX implementation.

Or use Rubyful Soup . . .

Filed under: Technology

Google Docs: Generate XHTML!

29
Aug/07
0

Dear Google Docs,

It sure would be nice if a published document was in XHTML!

Your friend,

John

Filed under: Technology

Distributed media – through vendors or standards?

22
Aug/07
0

Fred Wilson rightly asks that his content be distributed in chunks which are spread across the web, and might be reconstituted through software. One of his concerns is that comments should also be distributed, but aggregatable (since “aggregatable” is not really a word, let us say: collectable).

[Optional digression: Let me just point out that this fantasy of assembling all of the little bits is an old fantasy: As John Milton put it in Areopagitica (1644), we must remember

how they dealt with the good Osiris, took the virgin
Truth, hewed her lovely form into a thousand pieces, and scattered them
to the four winds. From that time ever since, the sad friends of Truth,
such as durst appear, imitating the careful search that Isis made for
the mangled body of Osiris, went up and down gathering up limb by limb,
still as they could find them. [Project Gutenberg]

Tough job! Now back to reality.]

Wilson’s strategy is to think about aggregated comments by using a particular service or vendor, such as Disqus. Or, it would seem, if there is a better service, he would use that.

What is strange to my ear is the attempt to find a solution through a vendor or a particular implementation. Let the marketplace supply particular solutions, Fred would say, and we pick the best ones. Maybe we invest in them, too.

But maybe because Wilson is a VC and not an engineer, he can’t pose the challenge as a request for a new standard, supporting broad interoperability. I.e., were a commenting mechanism built into the structure of the web or some higher abstraction, then there would be a basis on which to mix and match these kinds of products. I’m sure Disqus is great, but surely Disqus will be something of a walled garden, where the data is accessible only through their API, even if you can export the content to get out of their particular garden.

Another example of this would be transclusion. Great idea, and the people at Purple Wiki explain it as well as anyone. But wouldn’t it be something if this was built into the web itself?

Now I have myself in a corner, because I know the reality of standards. If the community calls for one, it gets created by a committee, and it will frequently suck. The great standards were, for the most part, written by one or two people, and typically came from the frontiers of the commercial Internet (if not prior to the advent of the commercial Internet), e.g., academia. I’m thinking about HTTP (Tim Berners-Lee) or MIME (Nathaniel Borenstein). And transclusion would fall in the same category, since it was thought up by Ted Nelson in his research era.

So Norman’s Request (if I might be so humble) would be: When you find you need something in the distributed plumbing of the network, ask a smart person to write an RFC. Then flog that. But if you go after the vendors, you’ll find yourself in another cycle altogether that starts with walled gardens, and then after a long wait you get a Frankenstein-like standard that no one but rich companies can support (and at that point, they’re the only ones who get to contribute to the standard!).

Filed under: Technology

Battling Intervals (Book Review)

22
Aug/07
0

Stuart Isacoff, Temperament: How Music Became a Battlefield for the Great Minds of Western Civilization (2001, 2003). $13.95. [Amazon]

Go over to your piano and play a middle C. Now play the next higher C. That’s an octave difference; the string for the lower C should be twice as long as the higher one. That’s a 2:1 ratio. Another ratio is to play the C, and then play the higher G. That’s a fifth, and the ratio of the lengths should be 3:2. Pythagoras — or his school — figured all that out in the 6th century B.C.E. But here’s the bad news. Produce a series of octaves where you keep halving the length of the string, and see what it sounds like after you’ve done it seven times. Now do the same thing with the fifths. This time, you will need to do twelve times. Pythagoras believed that you would arrive at the same final tone (i.e., tone with the same name) at the end. But guess what? You don’t:

The tones sounded by his two instruments were, however, almost the same, yet slightly — disturbingly — out of tune. The fact is, octaves and fifths, when created with Pythagoras’s pure mathematical ratios, are incommensurate: The further they move away from a common starting point, the more the structures built from these “perfect” intervals diverge. (40)

Thus ensues centuries of argument between those who seek to keep the standard octaves and fifths, and those who advocated something that came to be called “equal temperament,” where the distance between the tones are fixed, and, apparently, you can’t hear the slight dissonaces that are introduced. It’s this equal temperament that your modern piano uses. In this great argument are major players such as Descartes, Mersenne, Vincenzo Galilei (Galileo’s father), Rousseau, Rameau, and many others. They really go at it. I know these figures from the history of science and philosophy, and it was amazing to me to see how invested they were in music; this probably says something about how intellectual disciplines isolate their objects of study like so many individual bees — you forget the variety of flowers they serviced. On the one hand, it would seem, are those who might be called the Pythagoreans, who believe that there is some mystical force in the “just” intervals. And there are the moderns, who advocate equal temperament.

The first half of this book is great, as you see the Pythagorean ideal crumble when faced with the prospect of constructing a playable keyboard– the illustrations are outrageous (the key ones are woodcuts or engravings from Marin Mersenne’s Harmonie Universalle [1636-1637]; try as I might, I couldn’t find reproductions on the mighty Internet). The 2nd half gets a bit tedious, with many digressions, but still worthy if you can stick it out. There are nuggets all the way through, and having finished it, I can say that I’m just about dying to listen to a couple of things: Adrian Willaert’s Quid non ebrietas (16th century), which was apparently designed to show the pain of just intervals, and then some new pieces by Michael Harrison, a sometime collaborator of La Monte Young, which strives to evoke the mysticism and physical sensation of the early systems.

I’ll close this with a juicy quote from d’Alembert:

All freedoms are bound together and are equally dangerous. Freedom in music implies freedom to feel, freedom to feel implies freedom to think, freedom to think implies freedom to act. (223-224)

Amen.

Escape 9-5, Live Anywhere, and Join the New Rich (Book Review)

19
Aug/07
0

Timothy Ferriss, The 4-Hour Workweek (2007) . $19.95.

This is a provocative book which I hereby recommend to all of my friends, colleagues, acquaintances, and students . . . especially my younger friends. The book looks like a business self-help / how-to-succeed / make-money-quick book — the type of book my friend Paulina Borsook calls “business porn” — but it is subtly different.

In many ways the book is yet another book of organizational trivia: How to systematize your time, life, and money better, or, specifically, how to eliminate almost all of the tedium but still make your monthly nut. On this basis a lot of people would say that it’s a silly read, because there are a million books out there with all of the same stuff (e.g., all those little “getting things done” rules like don’t read e-mail right when you get to work; batch it, etc., etc.).

The main way the book is different is because of its existential realism about the reason for needing to escape everyday tedium (others would call this existential realism “cynicism” or “nihilism” or possibly even “atheism”). At the end of the book, Ferriss talks about how he deals with the “big questions,” such as “what is the meaning of life?” He suggests that if you (1) can’t define the meaning of the question with clarity, and/or (2) can’t define the consequences of what an answer would entail, then the question is pointless. With this stroke, he brackets a great deal of navel-gazing and anxiety. At the same time, he advises taking a spiritual retreat, but more to leave the world’s cares behind that to get answers. I was not surprised that this section of the book is headed by a quotation from Victor Frankl. All of this is smuggled in at the end. I think I know why.

Why? Because most people who are working 80-hour weeks aren’t in the position to even formulate a good philosophical question, let alone think about it or evaluate some answers. The reason to reorganize your life into a 4-hour work week is to give you the freedom to . . . do what you want, which might well include such philosophizing. As Marx said in the famous passage in the German Ideology (1845), we need a way of living that

makes it possible for me to do one thing today and another tomorrow, to hunt in the morning, fish in the afternoon, rear cattle in the evening, criticise after dinner, just as I have a mind, without ever becoming hunter, fisherman, herdsman or critic.

For Ferriss, the freedom he has gained through his method is devoted to learning and service, and I suspect he will have a lot more to say about such topics in future books. I suppose the sad fact is that Ferriss’s personal utopia is nestled within and enabled by what used to be called late capitalism, but at this point, that’s all we’ve got.

OK, as for the “content” of the book. The book says: Figure out a product. Why? Because if you’re in a service or consulting or wage-labor business, you’re always engaged in needless communication, and you don’t get the upside. The best thing about a product is that once it’s done, you just sell it. (And guess what, you can pay other people to sell it.) If you can get the profit high enough, you may be able to automate the whole thing. Ferriss provides lists of resources for creating a professional profile for yourself, creating “expertise,” getting a web-based presence, advertising your product, outsourcing payment and fulfillment: A 360-degree view of automating your business. (In the area of product definition and validation, the book is very much like a miniature version of Cooper’s Winning at New Products, with the key difference that Ferriss is trying to set up a business that will return a relatively small monthly return — a personal life-style business.)

After the business setup stuff, he gets into the fruits of that labor, i.e., what do you do during the rest of the week not occupied with your 4 hours of management. There are some interesting parallels here with the outsourcing argument in the business section: I.e., just as there are deals overseas to automate your business, similarly you can conduct geo-arbitrage to get deals for sitting on a beach or in a cafe.

Filed under: Reading, Reviews

Sorting Google search results by date?

17
Aug/07
0

Google questions:

I wonder why you can’t ask to have your search results returned by date (say, date found by the spider — whatever) rather than relevance? (To be sure, you can specify the window of dates you want to search . . .)

I wonder why one doesn’t see a numeric score for relevance? (Doubtless the answer is because it would provide too much information to SEO manipulators.)

Interestingly, Microsoft’s new search offering provides some techniques for weighting the results, which helps.

search.live.com - ability to weight search results

Filed under: Technology

The Google

17
Aug/07
0

Ah, so this is how you refer to the search engine company.

The Google

Filed under: Technology

Pragmatic Programmer Dave Thomas writes history of Michigan State

17
Aug/07
0

Wow, I didn’t know the Pragmatic Programmers (Dave Thomas and Andy Hunt) have turned to writing histories of institutions of higher education.

Amazon PP Rec

Filed under: Technology

Yet (yet) another Boston Ruby on Rails shop

17
Aug/07
0

Is there anyone in Boston doing going old J2EE, LAMP, etc.? I guess not. Pete Glyman, co-founder of Geezeo, is hunting down great Ruby on Rails developers . . . He says that the kinds “of things that are good to know [are] …Ruby on Rails (duh), MySQL, Subversion and Capistrano, RJS, Scriptaculous/prototype libraries and basic unix/linux. Even if you’re new to rails that’s cool… passion, enthusiasm and a willingness to learn and grow with our team are most important.” According to their “about” page, “Geezeo helps people make ‘Educated Financial Decisions,’” which seems like a good idea to me. One thing I like about this solicitation is that it contextualizes passion a bit more than other postings we’ve seen lately.

Filed under: Technology