Well, I don't use RoR or treeview, so my advice is more general...

  jQuery("#prop-tree").treeview({
                url: "tree/self_and_children"
      });

a) No idea what this actually achieves, but I think the goal is to set
the content type header.
 Using Firefox (with Firebug/Developer Extensions) you can check if
the content type header is set correctly.

Also, using firebug, you can look at the result sent back via Ajax,
and paste it into the console to see if it's valid JSON/javascript.

Hope that helps...




On May 7, 2:05 pm, "Max Williams (Brighton)"
<[EMAIL PROTECTED]> wrote:
> 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

Reply via email to