From: Phil Tayo Date: 2010-02-17T09:07:54+09:00 Subject: Convert Sequel Dataset to JSON Object Hi, I'm trying to do an AJAX request from my xhtml page to a controller. The AJAX request passes "id=idgoeshere" where idgoeshere is a number. Inspecting in Chrome inspector shows me that the id is being passed so no problems there. The problem I have is when I try to get my controller to return some data. I'm using Sequel as my DB and my controller runs a query and is then supposed to output a json formatted object but I can't get it to work. I've tried a few things already: 1. Task.filter('id < ?', id).each do |task| "{\"task\" : \"#{task.task}\",\"createdat\" : \"#{task.created_at}\", \"id\" : \"#{task.id}\" }" end Generates: # 2. Task.filter('id < ?', id).each { |task| "{\"task\" : \"#{task.task}\",\"createdat\" : \"#{task.created_at}\", \"id\" : \"#{task.id}\" }" } Generates: # I installd the JSON gem and have tried the next two: 3. json = JSON.generate(Task.filter('id < ?', id)) json Generates error: JSON::GeneratorError: only generation of JSON objects or arrays allowed 4. json = JSON.generate(Task.filter('id < ?', id).to_a) json Generates: ["#","#".....etc] What I'm trying to return to my xhtml is a JSON object containing all of my tasks that are returned from the DB, does anyone have any pointers on how to do it? Thanks in advance! Btw, I'm using Ramaze framework but I don't think this is a Ramaze framework issue so I'm posting it here... -- Posted via http://www.ruby-forum.com/.