2013-07-28 57 views
2

我無法通過更新處理程序發佈到CouchDB,我不知道我做錯了什麼。以下是詳細描述。通過更新處理程序無法正常工作提交表單到couchDB

我使用erica創建了一個應用程序,其中的細節主要來自wiki。它工作得很好,直到我決定去張貼,但服務器端,通過更新處理根據Apache CouchDB wiki Working_with_Forms

我創建了一個新的「Web應用程序」與埃裏卡,構建索引(切正膏會從維基,有小的改變):

<!DOCTYPE html> 
<html lang="en"> 
<head> 
<meta charset="utf-8"> 
<title>Minimal Form</title> 
</head> 

<body> 
<div id="contact-form"> 
    <form id="contact" method="post" action="/mydatabase/_design/mydesigndoc/_update/postForm" enctype="multipart/form-data"> 
    <fieldset> 
     <label for="name">name</label> 
     <input type="text" name="name" placeholder="Full Name" title="Enter your name" class="required"> 

     <label for="phone">phone</label> 
     <input type="tel" name="phone" placeholder="+1 (555) 555-5555" required="" pattern="\+?[0-9)(-]+"> 

     <label for="email">e-mail</label> 
     <input type="email" name="email" placeholder="[email protected]" title="e-mail address" class="required email"> 

     <label for="blog">blog</label> 
     <input type="url" name="url" placeholder="http://"> 

     <label for="message">message</label> 
     <textarea name="message"></textarea> 

     <input type="submit" name="submit" class="button" id="submit" value="submit"> 
    </fieldset> 
    </form> 
</div> 

我改變了形狀屬性action=到:htttp://localhost:5984/DBNAME/_design/DESIGNDOCID/_update/UPDATENAME並加入enctype="multipart/form-data"

然後,_design文件構造,根據維基,像這樣:

{ 
updates: { 
    postForm: function(previous, request) { 

     /* during development and testing you can write data to couch.log 
    log({"previous": previous}) 
    log({"request": request}) 
    */ 
    var doc = {} 
    if (!previous) { 
      // there's no existing document _id as we are not using PUT 
      // let's use the email address as the _id instead 
      if (request.form && request.form.email) { 
       // Extract the JSON-parsed form from the request 
       // and add in the user's email as docid 
       doc = request.form 
       doc._id = request.form.email 
      } 
     } 
     return [doc, toJSON({ 
      "request": request, 
      "previous": previous, 
      "doc": doc 
     })] 
    } 
} 
} 

這被放置在「ddoc」 -folder,推該應用的ERICA,打開網頁根據鏈路發現的形式,但它被提交時這是回答我:

{"error":"unnamed_error","reason":"(new TypeError(\"point is undefined\", \"/usr/share/couchdb/server/main.js\", 1475))"} 

我已經用行動擺弄周圍=「...」屬性,甚至把絕對ADRESS這樣的:

http://localhost:5984/mydatabase... 

我用json.stringify()替換了toJSON()。

我已重新啓動該過程,並重新完成了項目。無濟於事。

我有明顯的感覺,我已經「失明」,並且解決方案可能只是在我眼前,但我看不到它。似乎POST-http請求沒有問題,導致服務器在我嘗試使用AJAX(忘記「content-type」)之前抱怨過,但這次它似乎是內部服務器問題。我沒有線索。真。

總而言之,問題是:有人能幫助我嗎?請。

+0

我知道這是一個很長的描述。正如我已閱讀本網站上的各種帖子,我發現最常見的評論是問題/描述是模糊的和/或需要闡述。所以我做了。 它太長/詳細?我應該減少以獲得答案嗎? –

+0

我知道這是一個古老的問題,但自從你問:是的。請減少描述。只包括相關的細節。我已經爲你做了一些編輯。 – Flimzy

回答

2

我會回答我自己的問題,同時請求那些浪費時間的人的原諒。

我所做的是我通讀了kanso並瞭解範圍的概念如何適用於這種情況。這是在更新處理程序上使用exports的問題,因此可以通過<form action="/database/_design/designDocument/_update/updateFunction進行訪問。

爲什麼我之前沒有閱讀Kan.so?那麼,我的想法就是保持簡單 - ericacouchapp的繼任者我決定這將是一個合理的舉措,以保持基本的過程。儘管我必須說文檔是稀缺的,所以通過閱讀Kan.so,除了揭示了couchapp構建的神奇之外,我還介紹了其他幾個漂亮的概念和技術。我感激地鞠躬。

我希望所有那些花時間閱讀我的冗長的文章,結果是,不必要的問題將會以我的無知來監督。

(現在我只是不知道是否有某種聯繫/主持人誰可以處理我的著作,以避免未來TIMEL OSS)

+0

感謝您的支持。我遇到了同樣的問題,你的回答將幫助我找到解決辦法! – configurator

2

我也遇到了這個錯誤,是什麼原因造成的,如在通過@暗示豌豆莢,在couchapp的設計文件中沒有正確定義你的exports。在我們的例子中,它是列表函數,無法調用,而是在couchdb日誌中顯示500錯誤,其中Type errorpoint is undefined

我們使用kanso,並在app.js中我們不需要列表文件。我們有:

module.exports = { 
    rewrites: require('./rewrites'), 
    views: require('./views'), 
    shows: require('./shows') 
}; 

將其更改爲以下解決了這個問題:

module.exports = { 
    rewrites: require('./rewrites'), 
    views: require('./views'), 
    shows: require('./shows'), 
    lists: require('./lists') 
}; 

我可以建議版主改變這個問題的標題包括point is undefined這是上面顯示出錯誤CouchDB日誌何時發生這種類型的錯誤,以幫助其他人更輕鬆地找到它?