Tuesday, March 10, 2009

Merb + CouchDB Does Work After All

‹prev | My Chain | next›

I had the BMore on Rails meeting tonight, so this link in the chain will be somewhat light. It does not matter the amount, just the presence.

When trying to get Merb to hit against existing data in a CouchDB database, I ran into trouble. The operative point being existing data in this case. The Couch DB DataMapper adapter expects (requires) that the data be decorated with a couchdb_type attribute. Any records created with the adapter have that attribute, but, obviously, my hand created records did not have it. Once I added it, Merb pulled data back from CouchDB with ease.

By way of summary, what I needed (in addition to the generated code detailed last night) was a Meal data class:
class Meal
include DataMapper::CouchResource

property :title, String
property :date, String
property :summary, String
property :description, String
end


And a show template:
<h1><%= @meal.title %></h1>

<p>We enjoyed this meal on <%= @meal.date %></p>

<p><%= @meal.summary %></p>

<p><%= @meal.description %></p>
Then, I can verify that we are correctly retrieving data from CouchDB and populating the template with a browser:

No comments:

Post a Comment