Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting couchrest and couch_potato to recognize existing couchdb documents
    text
    copied!<p>I'm trying to create a basic Rails CRUD app against a CouchDB database hosted on Cloudant. </p> <p>I'm using <a href="https://github.com/langalex/couch_potato" rel="nofollow">couch_potato</a> as my persistence layer and have it connecting properly to my Cloudant database. </p> <p>The issues I'm having is my first model won't see the existing documents in my CouchDB database, <em>unless</em> I add a <code>ruby_class</code> field that equals the name of my model. </p> <p><strong>My simple User model:</strong></p> <pre><code>class User include CouchPotato::Persistence property :id, :type =&gt; Fixnum property :FullName, :type =&gt; String view :all, :key =&gt; :FullName end </code></pre> <p><strong>Sample CouchDB document:</strong></p> <pre><code>{ "_id": 123456, "_rev": "4-b96f36763934ce7c469abbc6fa05aaf3", "ORGID": 400638, "MyOrgToken": "19fc342d50f9d8df1ecd5e5404f5e5f7", "FullName": "Jane Doe", "Phone": "555-555-5555", "MemberNumber": 123456, "Email": "jane@example.com", "LoginPWHash": "14a3ccc0e6a50135ef391608e786f4e8" } </code></pre> <p>Now, when I use my <code>all</code> view from the rails console, I don't get any results back:</p> <pre><code>1.9.2-p290 :002 &gt; CouchPotato.database.view User.all =&gt; [] </code></pre> <p>If I add the field and value <code>"ruby_class: User"</code> to the above CouchDB document, then I get results back in the console:</p> <pre><code>1.9.2-p290 :003 &gt; CouchPotato.database.view User.all =&gt; [#&lt;User _id: "123456", _rev: "4-b96f36763934ce7c469abbc6fa05aaf3", created_at: nil, updated_at: nil, id: "123456", FullName: "Jane Doe"&gt;] </code></pre> <p>I'm working with a large set of customer data, and I don't want to write any scripts to add the <code>ruby_class</code> field to every document (and I may not be permitted to). </p> <p>How can I get my app to recognize these existing CouchDB documents without adding the <code>ruby_class</code> field?</p> <p>I couldn't find much documentation for couch_potato and couchrest that shows how to work with existing CouchDB databases. Most of the examples assume you're starting your project and database(s) from scratch.</p> <p>Thanks,</p> <p>/floatnspace</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload