You need to include additional headers in the POST request to indicate
that the view language is JSON, like so:

db.post('_temp_view', <<EOJS, 'content-type' => 'application/json')
function(doc) {
    ...
}
EOJS

Dunno know if couch_object supports this, but you can use Net::HTTP to
do the same thing:

Net::HTTP.start(host, port) do |http|
    http.post('/' + dbname + '/_temp_view', <<-EOJS, 'content-type' =>
'application/json')
        function(doc) {
            ...
        }
    EOJS
end

K.

On Sun, Oct 5, 2008 at 1:47 PM, Paola Lorusso <[EMAIL PROTECTED]> wrote:
> Hi ,
> I' am trying to use couchdb with ruby. I am using in particular 
> 'couch_object' to interface ruby with couchdb.
> I would ask how I can create views in ruby instead of javascript to query 
> couchdb.
> In particular I am interested to faster this query following below that 
> queries a blog db, where I have posted comments, posts, and authors.
>
>
> results1 = Array.new
>     for post in posts
>          id = post["id"]
>          doc = db.get(id).to_document
>      if doc["type"] == 'post' and doc["title"][0..1]== /xr/ then results1 = 
> doc end
> end
>
> I have read samewhere that I can optimize the performance using views. May I 
> do that following this example?
>
> I have seen same exemples on this URL 
> http://theexciter.com/articles/couchdb-views-in-ruby-instead-of-javascript ,  
> but when I have tried them there were errors.
>
> I have try to post a view to
> response = db.post("_temp_view", <<EOJS)
> function(doc){
>      return doc
>  }
> }
> EOJS
>
> Infact, I have this problem:
> #<CouchObject::Response:0xb6deb370 @response=#<Net::HTTPInternalServerError 
> 500 Internal Server Error readbody=true>, 
> @parsed_body={"error"=>"query_language_unknown", 
> "reason"=>"application/json"}>
>
> In any case I would prefer to use ruby instead of javascript to query couchdb.
>
> Can you halp me?
> Thanks
>
> Paola
>
>
>
>      Scopri il blog di Yahoo! Mail:
> Trucchi, novità e la tua opinione.
> http://www.ymailblogit.com/blog

Reply via email to