It sounds like you're trying to debug three things at once: * Can I generate valid JSON from my Rails app?
* Can I get a JSON download to work with JavaScript and jQuery? * Can I get async JSON to work with treeview? I would simplfy the debugging problem by separating those three questions and tackling them one at a time. That will make it a lot easier to track down the problem. For example, you can test the first one all by itself by generating your JSON data and simply copying and pasting it into www.jsonlint.com to see if it accepts it. That way you don't even have to think about JavaScript at all; you are simply debugging your Rails app. Once you know you have good JSON data, you can test question #2 with a simple test case that just downloads the JSON data with jQuery and displays it (even with just a console.log call). Finally, with all that working, you can tackle the treeview question. -Mike > From: Max Williams (Brighton) > > Hi - first of all this is a plugin-specific question (about treeview) > - i sent it to the plugin discussion page but it seems pretty > dead (no posts for over a year), so i'm sending it here as > well. If anyone could help me out that would be fantastic. > > I've been using treeview and have no problems with it so far. > However, to get better performance i'm now trying to switch > to the asynchronous version: > http://jquery.bassistance.de/treeview/demo/async.html > > In the example they use php to return some json to the tree, > but i'm using it in a ruby on rails app, and can;t work out > how to get it to work. Can anyone help? I'm really just not > sure how to get the required json for the update back to the treeview. > > This is what i'm doing at the moment: > > In the view: > > jQuery(document).ready(function(){ > jQuery("#prop-tree").treeview({ > url: "tree/self_and_children" > }); > }); > > ... > <ul id="prop-tree"> > </ul> > > The url "tree/self_and_children" does seem to be calling the > correct controller and action, which is as follows: > > def self_and_children > # expects the id of the branch which is clicked on, which > will be something like > # "property_id_79". We want property with id 79. > if params[:id] > property = Property.find(params[:id].split("_").last) > else > property = Property.root > end > > @json = property.self_and_children_to_json > respond_to do |format| > if @json > #should never get an html request for this > format.html { render :text => @json } > format.xml { head :ok } > format.js { render :text => @json } > else > format.html { } > format.xml { render :xml => @json.errors, :status => > :unprocessable_entity } > format.js > end > end > end > > But, nothing comes back - at least, the tree doesn't change. > My questions are as follows: > > a) is doing "render :text => @json" the proper way to send > back the chunk of json to treeview? Should i do something in > a js.rjs file instead? > b) how do i send through the id of the clicked-on branch to > the controller? (and retrieve it in the controller) > > thanks in advance > max >