Couch Potato View All Not Working

26 views
Skip to first unread message

Linicks

unread,
May 14, 2010, 1:52:18 PM5/14/10
to couchpotato
All,
I'm just starting to work with Rails3 Beta3 and couch_potato
0.2.31. I've started to create a very simple application to get a
feel for couch potato. I've created a model:

class Entry
include CouchPotato::Persistence

property :device, :type => :string

view :all, :key => :created_at
end

I've successfully created a couple of objects from the rails console,
but when I try to retrieve the values from the view I get the
following error:

-------------------------- Begin -------------------------
Loading development environment (Rails 3.0.0.beta3)
irb(main):001:0> CouchPotato.database.view Entry.all
TypeError: class or module required
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/type_caster.rb:25:in `instance_of?'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/type_caster.rb:25:in `cast_native'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/type_caster.rb:8:in `cast'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/simple_property.rb:54:in `device='
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/simple_property.rb:16:in `send'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/simple_property.rb:16:in `build'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/json.rb:39:in `json_create'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/properties.rb:17:in `each'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/properties.rb:17:in `each'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/json.rb:38:in `json_create'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/properties.rb:64:in `json_create'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/attachments.rb:25:in `json_create'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
persistence/ghost_attributes.rb:7:in `json_create'
from /usr/lib/ruby/gems/1.8/gems/json-1.4.3/lib/json/common.rb:146:in
`parse'
from /usr/lib/ruby/gems/1.8/gems/json-1.4.3/lib/json/common.rb:146:in
`parse'
from /usr/lib/ruby/gems/1.8/gems/couchrest-0.37/lib/couchrest/core/
rest_api.rb:18:in `get'
from /usr/lib/ruby/gems/1.8/gems/couchrest-0.37/lib/couchrest/core/
database.rb:88:in `view'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
view/view_query.rb:56:in `query_view_without_class_reloading'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/rails/
reload_classes.rb:25:in `query_view'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/rails/
reload_classes.rb:8:in `with_class_reloading'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/rails/
reload_classes.rb:24:in `query_view'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
view/view_query.rb:16:in `query_view!'
from /usr/lib/ruby/gems/1.8/gems/couch_potato-0.2.31/lib/couch_potato/
database.rb:47:in `view'
from (irb):1irb(main):002:0>
irb(main):003:0*

------------- End ---------------------------------

Here is the view souce that was created in CouchDB:

{
"_id": "_design/entry",
"_rev": "1-cbeb90609f3d2efa10b5e22177054d4e",
"language": "javascript",
"views": {
"all": {
"reduce": "function(key, values) {\u000a return
sum(values);\u000a }",
"map": "function(doc) {\u000a if(doc.ruby_class
&& doc.ruby_class == 'Entry') {\u000a
emit(doc['created_at'], 1);\u000a }\u000a }"
}
}
}



Your advice is appreciated!

Mathias Meyer

unread,
May 15, 2010, 4:54:46 AM5/15/10
to couchpo...@googlegroups.com
On Fri, May 14, 2010 at 7:52 PM, Linicks <lin...@gmail.com> wrote:
> All,
>  I'm just starting to work with Rails3 Beta3 and couch_potato
> 0.2.31.  I've started to create a very simple application to get a
> feel for couch potato.  I've created a model:
>
> class Entry
>  include CouchPotato::Persistence
>
>  property :device, :type => :string
>
>  view :all, :key => :created_at
> end
>
Hi,

no need to specify the type here, just property :device, CouchPotato
will deal with native types like strings automatically. Plus, the type
would have to be a class, so :type => String, and not a symbol.

Cheers, Mathias
--
http://scalarium.com | http://paperplanes.de
http://twitter.com/roidrage

Linicks

unread,
May 17, 2010, 5:56:19 PM5/17/10
to couchpotato
Mathias

> On Fri, May 14, 2010 at 7:52 PM, Linicks <lini...@gmail.com> wrote:
> > All,
> >  I'm just starting to work with Rails3 Beta3 and couch_potato
> > 0.2.31.  I've started to create a very simple application to get a
> > feel for couch potato.  I've created a model:
>
> > class Entry
> >  include CouchPotato::Persistence
>
> >  property :device, :type => :string
>
> >  view :all, :key => :created_at
> > end
>
> Hi,
>
> no need to specify the type here, just property :device, CouchPotato
> will deal with native types like strings automatically. Plus, the type
> would have to be a class, so :type => String, and not a symbol.

I made the changes that you recommended, and I believe that things are
working properly now. I'm not sure where my train of thought was at
the time, but I think I may have been confused by this example:

class User
property :name
property :bio

view :all, :key => :created_at, :properties => [:name], :type
=> :properties
end

Is there a basic demo application like a blog using couch_potato that
can be used for a reference? Being new to CouchDB and Couch Potato,
it would be very helpful to have as a clear use pattern of the API for
those dipping there toes into the "NoSQL" water for the first time.

Many thanks for the clarification/help!

-Nick

>
> Cheers, Mathias
> --http://scalarium.com|http://paperplanes.dehttp://twitter.com/roidrage

langalex

unread,
May 17, 2010, 6:12:12 PM5/17/10
to couchpotato
i wrote a small example app a while ago: http://github.com/langalex/couchfoto

cheers,
alex
Reply all
Reply to author
Forward
0 new messages