0

I am currently learning CouchDB and using the O'Reilly book as a guide to get started. I've been following it pretty thoroughly, however, upon working with Sofa, the book requires me to inspect what happens when we hit 'Save' on our edit template. The book says that I should see a success response (uses Firebug the button triggers the Put request), however, instead I get a "

{"error":"not_found","reason":"missing shows function new.html on design doc _design/sofa"}"

Now I only started reading this week and I know the answer might be obvious, but if someone could at least point me in the right direction (where in Sofa to add, fix a bug, patch) that would be great.

My initial guess is that I need to add a "new" shows function, but I just wanted some advice before I delve into this wild goose chase.

sorry if this is a noob question.


{"couchdb":"Welcome","uuid":"4d9b6082e16607a33dcbfdffb57503b5","version":"1.6.1","vendor":{"version":"1.6.1","name":"The Apache Software Foundation"}}

Downloaded the newest version of Sofa from (https://github.com/jchris/sofa)

Justin
  • 137
  • 1
  • 3
  • 10

1 Answers1

1

How to resolve the issue

The issue is that the page is being accessed from:

http://127.0.0.1:5984/myblogdb/_design/sofa/_show/edit

Access it instead from:

http://127.0.0.1:5984/myblogdb/_design/sofa/_show/edit/

(Your database name may differ from 'myblogdb'). Note the trailing backslash.

Explanation of why a show function called "new" is not necessary:

Take the following query to a show function:

http://127.0.0.1:5984/myblogdb/_design/sofa/_show/edit/This-is-a-second-post

This will call the function in edit.js and pass in the document with an _id of This-is-a-second-post, if such a document exists. If the document doesn't exists, as in the case of

http://127.0.0.1:5984/myblogdb/_design/sofa/_show/edit/new.html

Then edit.js sets up the data object passed to Mustache.to_html to have the correct fields for a new post.

Why it breaks in your case

When the edit show function is accessed via

http://127.0.0.1:5984/myblogdb/_design/sofa/_show/edit

The relatives paths to the scripts no longer work. Then the script defined in edit.html is no longer correct. As a result, the submit handler

$("form#new-post").submit(function() { ...

is no longer called. If it were called it would return false at the end, which prevents new.html from being POSTed.

Since it is not called, new.html ends up being POSTed, and that redirects the browser to

http://127.0.0.1:5984/myblogdb/_design/sofa/_show/new.html

which points to a non-existent show function, resulting in the error message you are seeing.