chris wrote:
> Now the javascript is being rendered out to the html page.
> #the controller method calling on the rjs file
What does show_tasks.rjs contain? It looks like that may be where your
problem is.
I should have asked you for both views, not just the .rjs. My apologies for the extra turn-around. Your rjs looks fine. What appears to be happening is that rjs is sending the correct stuff to the browser, but the browser is either expecting html rather than js and so is rendering it rather than executing it, or the browser doesn't know how to execute it. For case 1, check the method you're using to invoke the show_tasks method. If it's a link, for example, the method should be link_to_remote, not link_to. Your view needs to be using something that submits using XMLHttpRequest, not a straight POST or GET. That's how the browser knows to expect a js response that it should execute rather than simply display. If that's already in place, then check your application.rhtml or controller-specific layout if applicable. It needs to have this in the <head> section: <%= javascript_include_tag :defaults %>. That includes all the prototype js files you need for the browser to actually execute the js it receives.
As for the link_to, that is that thing that puzzles me, since the
links that appear are hard links to a separate page, it is the hard
links appearing that is contained within the ajax. I really don't
know why the javascript is rendering out there.
here is the main page, which has a list of categories on the left
side, then after clicking on one of them the ajax kicks in and shows
the related tasks on the right side
I should also add that the ajax is working fine when clicking on the
category links on the left side of the screen (no postback), it is
just the task items on the left side of the screen that then render
out javascript that is the problem. The html containing the rendered
ajax was using an addon in firefox to obtain the html contained within
the DOM, but not actually rendered out to the page. (that is kind of a
key point, not sure how I left it out before)
Not sure what you mean here. If the above is what you're referring to, there is no Ajax taking place via the category links. Clicking on the "Add Category" link sends a straight Http GET to the server. The server is sending back html which, because it sent a request using Http, the browser is rendering correctly.
it is just the task items on the left side of the screen
that then render out javascript that is the problem.
In both cases you're using straight links to invoke controller methods which causes the browser to expect an html response. The difference between the situation above and this one is that in the one above you're sending back html and in this one you're sending back js. So...
1) Assuming that you're category object is getting generated by enumerating a instance variable, I think if you replace the <a...></a> with
<%= link_to_remote(category.name, :url =>{:action => 'show_tasks', ::id => category}) %>
your problem will be fixed.
2) Spend the $9.95 to pick up Cody Fauser's RJS tutorial (in PDF) from O'Reilly. It'll put you on the right track.