Birds on Rails, Part 3

Saturday, December 3rd, 2005

Now I want to create a new page that lists all the species in the birds table. That is, it looks like this:

Brooklyn Bird Report Master Bird List

  • Fulvous Whistling-Duck Dendrocygna bicolor
  • Greater White-fronted Goose Anser albifrons
  • Snow Goose Chen caerulescens
  • Ross’s Goose Chen rossii
  • Brant Branta bernicla

This will live in the file /masterbirdlist.rhtml

How to do it? I begin by creating a regular HTML file named masterbirdlist.rhtml and putting it in the app/views/bbr directory, but that doesn’t work. It just tells me “Unknown action No action responded to masterbirdlist.rhtml.” OK. Looking back at the notes from Day 1, I see how to handle that. I add this method to the bbr_controller.rb file:

def masterbirdlist
  render_text "Hello"
end

Now I get “Hello” for the masterbirdlist. Of course that’s not what I want. I want to load the masterbirdlist.rhtml file. How do I do that? About this point I begin wondering what the manual says. Googling for it, it appears that there isn’t one. That compares very unfavorably with PHP and Java, both of which at least have documentation, not to mention reams of third party books available. (Later I found this site, but it doesn’t appear to be a true comprehensive manual; just a random collection of HowTos.) However, there does seem to be some API documentation which mentions render_file() methods. Maybe that’s what I need? No wait. I remember this now. I bet I have to generate a controller for the masterbirdlist:

~/Web sites/bbr$ script/generate controller masterbirdlist
      exists  app/controllers/
      exists  app/helpers/
      exists  app/views/masterbirdlist
      exists  test/functional/
   identical  app/controllers/masterbirdlist_controller.rb
   identical  test/functional/masterbirdlist_controller_test.rb
   identical  app/helpers/masterbirdlist_helper.rb

That seems to work. I thought this was just for mapping to database tables, but apparently it’s for all pages. This gives me the “Unknown action No action responded to index” at /masterbirdlist. But I’ll create a view for this in app/views/masterbirdlist/index.rhtml. Bingo! That works.

Now let’s add the code to generate the list of species:

<ul>

 <% @birds.each do |bird| %>
  <li><%= bird.common_name %></li>
 <% end %>
</ul>

This produces

NoMethodError in
Masterbirdlist#index

Showing app/views/masterbirdlist/index.rhtml where line #14 raised:

You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occured while evaluating nil.each

So now I have to create the birds variable. Thus I add this code to the masterbirdlist_controller.rb:

def index
  @birds = Bird.find_all
end

Now I get this error:

NameError in
Masterbirdlist#index

uninitialized constant Bird

I suspect this is because I haven’t mapped that table in Rails yet. i.e. I haven’t generated a model for the birds. Let’s do that:

$ script/generate model Bird
      exists  app/models/
      exists  test/unit/
      exists  test/fixtures/
      create  app/models/bird.rb
      create  test/unit/bird_test.rb
      create  test/fixtures/birds.yml

And now the page works. OK. I ‘m starting to get the hang of this. Adding the genus to the list is easy:

<% @birds.each do |bird| %>
  <li><%= bird.common_name %>  <i><%= bird.genus %></i></li>
 <% end %>

Now let’s add the species:

 <% @birds.each do |bird| %>
  <li><%= bird.common_name %>  <i><%= bird.genus bird.species %></i></li>
 <% end %>

Oops. That didn’t work:

ArgumentError in
Masterbirdlist#index

Showing app/views/masterbirdlist/index.rhtml where line #15 raised:

wrong number of arguments (1 for 0)

Hmm. Do I just need to put that in two separate tags or do I need to learn how to concatenate strings or terminate statements in Ruby? Concatenating seems to work; and it uses the plus sign, same as in Java:

 <% @birds.each do |bird| %>
  <li><%= bird.common_name %>  <i><%= bird.genus + bird.species %></i></li>
 <% end %>

However, it turns out I forgot a space, so I might as well just go ahead and use two tags anyway:

 <% @birds.each do |bird| %>
  <li><%= bird.common_name %>  <i><%= bird.genus %> <= bird.species %></i></li>
 <% end %>

I think that’s as far as I’m going to go tonight, but just maybe I am speeding up a little past what I could do with PHP (though I still don’t fully grok how the site is getting organized, and the URLs mapped.)

Birding Geneva, Part 3

Saturday, December 3rd, 2005

Friday Beth had a hair appointment in the morning and rehearsal in the afternoon. I dropped her off at the salon along with a brief list of hair related phrases in French I’d written up the night before since the hairdresser only spoke French and Italian. (Surprisingly, as international a city as Geneva is, people there were generally less comfortable in English than I’ve found in other cities like Antwerp, Amsterdam, Venice, or even Paris. Perhaps it’s because for the Swiss English may well be their third or even fourth language rather than their second. This was great for me since it meant I could practice my French. Beth, however, had a somewhat more difficult time.)

I began with a quick peek into the cemetery at the end of the street where we were staying, It wasn’t large, but had quite a few trees that hosted Common Blackbirds and Great Tits. Carrion Crows were also present, as they were most places in the city.

From there I walked down to the Rade once more, but this time I crossed over to the other side of the Lake before turning north. Mostly the same waterfowl as yesterday were present, with one new addition: a flock of Greylag Geese that has taken up residence on the Ile de Rousseau. Thanks to an unusual walkway beneath one of the bridges that dips below the water I got a goose’s eye view of these birds:

Greylag Geese in Lake Geneva

I walked along the Rade, spotting another new bird for the trip, a Pintail (in the U.S. we call this a Northern Pintail, but it’s the same species). Other Lake birds included Goosander, Little Grebe, Tufted Duck, European Coot, Mute Swan, Mallard, Black-headed Gull, Yellow-legged Gull, Great Cormorant, and Great Crested Grebe. There were multiple individuals of each of these species.

I continued walking to the Paquis, a sort of jetty across from the Jette d’eau on which there is a small (and I emphasize small) beach and some steam baths. At the right time of year, this is apparently a very good place for shore birds, as it’s the last beach on their migration south. However, by the day I arrived they’d all passed south. All I found were more goosanders, gulls, mallards, and house sparrows.

Continuing north, I entered Parc Mon Repos, the first in a long line of parks along this side of Lake Geneva. This provided the first Magpies of the trip. Magpies are fairly common in city parks in Western Europe, but somehow I’d managed to miss them till now. Great Tits and Blue Tits were also present, along with some European Robins.

Magpie in Parc Mon Repos, Geneva

The next park was La Perle du Lac. This included le Musée d’Histoire des Sciences, which had a really fascinating collection of scientific instruments. The surrounding also had some of the best birding. I picked up a lot of species here including my first and only woodpecker of the trip, a Great Spotted Woodpecker. Other birds found in the trees included Crested Tit, Blue Tit, Nuthatch, Chaffinch, Tree Creeper, and Song Thrush (another life bird).

I continued on into the Jardin Botanique where I immediately spotted a Wood Pigeon. It looks pretty much like a Rock Pigeon, only twice as big. Other birds found in the Gardens included Long-tailed Tit, Greenfinch, Coal Tit, Nuthatch, and European Jay.

European Jay in Jardin Botanique, Geneva

Past the Garden is the Chateau de l’Imperatrice. However this is not open to the public so I turned around and walked home.

That night Beth performed, and so her rehearsals were done. Saturday we took the train to Chateaux Chillon, a 11th century castle a couple of hours north of Geneva to do a little sightseeing. However, I took my binoculars and field guide with me just in case; and it’s a good thing too, because along with the now familiar Great Tits, Tufted Ducks, Goosanders, European Robins, and Great Crested Grebes, I spotted one more life bird flying back and forth along the shoreline leading up to the castle. I didn’t know what it was, and it didn’t look like anything I did know; but it was demonstrably shaking its whole hind end up and down, which suggested I should look in the section on wagtails. Yep, there it was: a Grey Wagtail, my final life bird of the trip.

Birding Geneva, Part 2

Thursday, December 1st, 2005

Thursday afternoon Beth had a rehearsal for her performance, so I went birding by myself along the East shore of Lake Geneva. This area is known as the Quai. I started roughly around the Jardin Anglais and walked a couple of miles along the shore through a marina and past the Jet d’eau (which may not be the world’s largest water fountain, but it’s got to be in the top ten).

Jette d\'eau in Lake Geneva

At this time of year (late October) Lake Geneva is full of waterfowl; and I spotted a number of relatively familiar species almost immediately:

  1. Tufted Duck (very common, related to our Ring-necked Duck)
  2. European Coot (essentially the same as American Coot except for an extra knob on its bill)
  3. Moorhen (also a U.S. bird)
  4. Mute Swan (native here, unlike the U.S. where it’s an exotic)
  5. Mallards (exactly the same as our Mallards)
  6. Black-headed Gull (the most common gull on Lake Geneva)
  7. Yellow-legged Gull (not nearly as common as in Venice)
    Yellow-legged Gull in Lake Geneva
  8. House Sparrow
  9. Rock Pigeon
  10. Great Cormorant
  11. Great Crested Grebe
    Great Crested Grebe in Lake Geneva
  12. Common Blackbird
  13. Little Grebe (The first life bird of this hike)
  14. Carrion Crow
    Carrion Crow in Lake Geneva

I was just getting ready to turn around when I stumbled onto the Parc La Grange, which was just off the edge of my map. However, it proved to be an excellent park for all sorts of passerines, especially tits and finches. I spent most of the rest of the afternoon there where I picked up:

  1. Common Teal (a subspecies of Green-winged teal or vice versa)
  2. Blue Tit
  3. Great Tit
  4. European Jay
  5. Crested Tit (a life bird)
  6. European Robin
  7. Marsh Tit (another lifer)
  8. Nuthatch
  9. Chaffinch
  10. Hawfinch (another lifer, and a hard one to get. Apparently these don’t sing very loudly and spend most of their time hiding in the tops of high trees. I was lucky enough to find one foraging in leaf litter on the ground.)
  11. Collared Dove

Toward the end of the afternoon, I exited the park and walked back the way I came along the shore of Lake Geneva. Mostly I spotted the same waterfowl I’d seen on the walk to the Park: coots, mallards, grebes, gulls, and the like. However I did also spot a Red-breasted Merganser back in the City Center. Fortunately I had the good sense to check this one in my field guide, which promptly informed me there weren’t any Red-breasted Mergansers in Lake Geneva. Instead I was looking at a Goosander, my tenth life bird for the day!

Goosander in Lake Geneva

In my defense, a Goosander really does look exactly like a Red-breasted Merganser except for a slight variation in the neck pattern. It’s obvious once you know what to look for, but it doesn’t jump out at you. Goosanders could probably show up every year in Jamaica Bay without anyone realizing they were here.

To Blog or Not To Blog

Thursday, December 1st, 2005

Cafe au Lait dates back to 1995. I know I’m not the first blogger. Ric Ford’s Macintouch precedes me, and probably others do as well. However, I was there quite early on, I think before the word “blog” was coined. Truth is I’ve never even really thought of Cafe au Lait, Cafe con Leche, and The Cafes as blogs, even after I added RSS feeds. Most obviously they’re organized by date rather than by post. And despite occasional off-topic posts, I mostly keep them focused on Java and XML respectively.

However, Mokka mit Schlag is very much a blog. It looks like a blog. It feels like a blog. It reads like a blog. Most importantly for me, it writes like a blog instead of a static set of web pages. Most importantly for you, the reader, it is no longer limited to one topic. Here I feel free to expound on any subject that wanders into my field of vision. I have carefully categorized posts so my birder friends can read about birds and my programmer friends can read about programming and my family can read my travel stories, without having to pay attention to the parts that don’t interest them; but I still get to write about anything I like; and that’s a good thing.