Ah, very good, Max, you're a step ahead of me on the debugging. Since you've narrowed it down to a Rails issue, would it make more sense to ask on a Rails list? Don't get me wrong, there are a number of Rails experts here who would probably be happy to help, it's just that you might get more focused assistance that way.
-Mike > From: Max Williams (Brighton) > > Hi Mike, thanks for your advice. In answer: > > 1) The JSON is valid (it was generated using rails .to_json > method and that site you recommended says it's valid) > > 2) I'm pretty sure a JSON download will work with JS/jQuery, > because the async treeview example uses a php script to > return some json - see > http://jquery.bassistance.de/treeview/demo/async.html, look > at the 'server component used' to see the php in question. > > 3) See 2. > > I'm confident that the json/jquery side of things is all > cool. My problem is purely rails-specific: how do i ask a > rails controller for a specific chunk of json, and how do i > send it back? Or, in other words, how do i manage in rails > what the example uses a php script for? > > thanks again > > On May 7, 4:57 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote: > > It sounds like you're trying to debug three things at once: > > > > * Can I generate valid JSON from myRailsapp? > > > > * Can I get a JSON download to work with JavaScript and jQuery? > > > > * Can I getasyncJSON to work withtreeview? > > > > 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 > > intowww.jsonlint.comto see if it accepts it. That way you > don't even > > have to think about JavaScript at all; you are simply > debugging yourRailsapp. > > > > 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 thetreeviewquestion. > > > > -Mike > > > > > From: Max Williams (Brighton) > > > > > Hi - first of all this is a plugin-specific question > (abouttreeview) > > > - 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 usingtreeviewand 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 onrailsapp, 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 thetreeview. > > > > > 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 totreeview? 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 >