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.

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.

Birds on Rails, Part 1

Sunday, November 27th, 2005

I’ve been working on reimplementing a web application for tracking bird reports in something modern. The current app is held together with Interbase, Delphi, payware e-mail libraries, and variety of handgrown scripts. There aren’t even any input forms that talk directly to the database. Instead you have to e-mail your reports in. The site is uploaded to the server after being statically generated from the database every five minutes or so. This was state of the art in 1995, I suppose. It’s a little questionable today, and the current maintainer/inventor wants to give it up. One of the problems with these sorts of applications is that they’re unmanageable by anybody other than the person who wrote them. Thus it seemed like time to reimplement all this in a slightly more standard manner.

I began by setting up the database tables in MySQL. The lack of foreign key constraints feels a little wrong since I have lots of detail tables in this app. However, it does make the initial data entry a little easier than it might otherwise be.

I tried writing some PHP pages, but that was more difficult than I expected so I thought I’d take a day and see if Ruby on Rails was all it was cracked up to be. I’d looked at it initially, but decided against it because IBiblio doesn’t yet support Ruby. But I’m prototyping this on my desktop Mac, and if Ruby makes my job a lot easier, I could find a different host. (more…)