Birds on Rails, Part 2

Wednesday, November 30th, 2005

Rails seems to be installed and working (Finally. That took almost a full day.) so let’s see if we can build some real pages. The first thing I need is something simple. I want to iterate through the sites table in the database and print each name in the site into an HTML unordered list. The SQL command is as follows:

SELECT name FROM sites

(It will be a little more complex in the future, but let’s start simple and add to it.)

Rails embeds Ruby code in HTML using <% %> and <%= %> markers. Here’s another downside. This is not well-formed XML. PHP correctly uses processing instructions for this. Rails should have copied from PHP instead of JSP/ASP.

So I went ahead and added this chunk of code to the index method that’s creating the main page by calling render :text.

 <% @sites.each do |site| %>
  <li><%= site.name %></li>
 <% end %>

Hmm, that completely didn’t work. Apparently I first need to create a view. That is, I need to create a file called index.rhtml in the app/views/bbr directory. Then I need to delete the index method in the bbr_controller.rb file. Then I put my Ruby code into the index.rhtml file instead. Then in bbr_controller.rb I put this code:

def index
  @sites = Site.find_all
end

This maps the sites variable to the sites table so I can reference it in the view rhtml file. And voila. The index page now pulls the list of site names out of the database and inserts them into the web page as desired.

Birding Geneva, Part 1

Wednesday, November 30th, 2005

Beth and I arrived in Geneva late Tuesday night on the Cisalpino. Wednesday we took a day trip to Lausanne. We climbed the Escaliers du Marché to the Cathédrale Notre-Dame, stopping along the way to look at a few Carrion Crows in a local park. Then we took the subway down to the lakefront and Olympic Park, where we enjoyed coffee and chestnuts, as well as some Mallards, Tufted Ducks, European Coots, Black-headed Gulls, Mute Swans, Great Cormorants, and two Grey Herons perched high in a tree.

Tufted Duck in Lausanne

By now we had adjusted to European time so Thursday we woke up in time to do a little early birding before Beth’s first rehearsal. We walked to the Parc des Bastions which is famous for its Murs des Réformateurs (Wall of the Reformers). This isn’t a large park, but it’s big enough to have a few interesting passerines. In fact, only two were familiar from the U.S., Rock Pigeon and House Sparrow.

Carrion crows were common. And almost immediately we found European Robin and Great Tit. We strolled down the main concourse of the park, which thoughtfully provided an excellent exhibit of Yann Arthus-Bertrand’s photographs entitled Earth from Above to distract Beth while I looked at birds from below. :-)

European Robin in Parc des Bastions

I quickly added Long-tailed Tit and Blue Tit. A Nuthatch was immediately obvious as a Nuthatch. Unlike the European Robin, this bird is clearly related to its American counterpart and was thus incredibly easy to find in the field guide. Next up was the Eurasian Tree Creeper, another bird that looks and behaves very much like its American counterpart Brown Creeper. Unfortunately it looks even more similar to the Short-toed Tree Creeper, and birds in the bush can be reliably distinguished only by voice. Since it didn’t sing (and since I wouldn’t recognize the song even if it did) I can’t be sure about this one. I do know it was a life bird. I just don’t know which one. :-(

The final bird for the Park was a Chaffinch, one of the most common European birds. However, it’s relatively non-descript compared to the tits; and I was not familiar with it, so I had to spot several more examples of it later in the trip before I became confident that’s what I’d seen.

We exited from the Southeast end of the Parc and walked over into old town to visit the Cathédral St-Pierre. There are some very interesting excavations underneath it. We left the cathedral and wandered back through the old city on the way to our Hotel and Beth’s rehearsal.

More CSS Layout Madness

Tuesday, November 29th, 2005

I remain convinced that the whole CSS layout mess was poorly thought out, poorly designed, and poorly explained. Yes, it’s hobbled by poor implementations too; but can you really blame the poor implementers when the spec writers could never explain exactly what they meant? Proof of this is just how incredibly difficult it is to reproduce simple, basic, liquid two column layouts any third grader can throw together in five minutes with tables.

The latest problem I’ve noticed comes on this site when the post is not long enough to match the sidebar. For example, take a look at Links Matter. The Google ads end up below the text instead of to the right as they should. Or the Mac category page where both the Feed list and the ads disappear below the text. That is the “column” shifts left as soon as possible.

There’s probably a break or clear or keep property I can set somewhere to make this come out right, as long as the font or window isn’t too big or too small, of course. But why should I have to? Why couldn’t CSS layouts be based on liquid nested tables like the ones proven to work by years of experience? Why invent something new? Note I am not suggesting that HTML tables be used for layout; only that CSS define its own table layout independently of any HTML tables in the document being styled? Not only would this be simpler to code against and implement. It would handle some tricky cases in three column layouts with large and small fonts that CSS still can’t manage. (See Cafe au Lait for one example.) Even Java has finally learned what’s been obvious to web designers for years: tables are the natural way to layout a page. However the W3C still hasn’t figured this out.

Oh well. It’s probably too late to fix this now. But please, if you ever find yourself inventing a new layout scheme, be it a stylesheet language, a GUI layout manager, or something else; please, please try to organize it around two-dimensional nested tables rather than something that only appears to be simpler.

Meanwhile I think I fixed it by floating the sidebar to the right at the same time the content was floated to the left. That is, I changed

#sidebar
{
	padding: 20px 10px 10px 0px;
	}

to

#sidebar
{
	padding: 20px 10px 10px 0px;
    float: right;
	}

This works, at least in Firefox. However In Safari, it pushed the sidebar always completely below the content. Back to the drawing board I guess.

Setting a permanent host name in Mac OS X

Tuesday, November 29th, 2005

Are you tired of host names like eliza-7.local in Mac OS X? Are you tied of seeing pointless dialogs like “eliza-7.local is already in use. Switching to eliza-8.local”? Do you want a stable hostname you put in scripts, MYSQL user tables, and so forth? If so add the following line to /etc/hostconfig:

HOSTNAME=eliza.elharo.com

Of course you’ll change eliza.elharo.com to the fully qualified domain name of your machine. You’ll need to use sudo to edit the file. On versions of Mac OS X prior to Tiger (10.3 and earlier) you may need to delete the existing HOSTNAME line as well.

It’s up to you whether or not to register the name with your local DNS server, though I find it convenient to do so. One more trick: it’s completely possible to register NAT addresses like 192.168.254.23 with external DNS servers like EasyDNS. You’ll only be able to connect to that system from within your local subnet (unless you’ve configured your firewall to forward external requests to that local address), but the DNS resolution still works.

Safari Breakage (+ a shoutout to IE)

Monday, November 28th, 2005

Hmm, seems some recent CSS change broke the sidebars in Safari 2 on Tiger. Safari’s CSS support is quite good; so it’s more than likely my bug (though Firefox does render this site as I expect). I’ll try and figure out what’s going on and fix it. In the meantime, if anyone is using Internet Explorer to view this site, please let me know how it looks. Thanks.

OK. I see the problem. It’s this rule for the search form text field:

#sidebar #searchform #s {
	width: 55%;
	padding: 2px;
	}

I can change that to

#sidebar #searchform #s {
	width: 15%;
	padding: 2px;
	}

Then Safari works. However, the search box gets too small in Firefox. I suspect the two browsers are measuring that 15/55% against different elements. One’s probably measuring against the page and one against the parent, or some such. So let’s try font-relative units instead. 8 em should work nicely:

#sidebar #searchform #s {
	width: 8em;
	padding: 2px;
	}

That looks about right and seems to work well in both browsers.

Links Matter

Monday, November 28th, 2005

Most of my sites and articles get incredibly high placement in Google given reasonably specific search terms, generally in the top 10. However, this site is quite new and isn’t really linked from anywhere yet, and the effects on Google searches have been surprising. Basically this site is invisible unless you throw in “site:elharo.com”. This is true not just for topics where there’s a lot of competition like Ruby on Rails, but for much less obvious topics like Birding Venice. Google does have the site (though apparently not all the pages) in its index. It just doesn’t think it’s very important yet. Hopefully this will change as people begin to visit this site.