Don't use link_to_remote, it's deprecated in rails 3. If you were in rails 2 that'd be fine.
You don't need link_to, since we're going to link to a part of the page that's hidden, we can just make things simple and use html anchor tag.
Let's make this much simpler. If you're partial is not very big, just load it in on page load and give it style display:none.
<div id="toggle_div" style="display:none"> <!-- using external stylesheets of course -->
<%= render partial => "your_partial" %>
This way, the div will be hidden and no one can see it until they click on the link which will trigger the toggle action.
Then, (if you're using jQuery *****)
// notice the hash(#) and dot(.) before the elements? A hash represents an HTML ID and a
// dot represents an HTML class. I made the link have a class, and the toggle_div an ID
// but you may use whatever you'd like, just make sure if you're referencing an ID that you put
// a hash(#) before it and if you're referencing a class, make sure you put a dot(.) before it.
// this makes for cleaner, separated, more modular code.
And that's it!
If you want to do this ajax (I'd recommend doing it without ajax so long as the partial is small and you're only doing this once or twice on the page) you can use jQuery ajax methods. $.get comes to mind.
Also, if this isn't working, it's probably cause you don't have jQuery setup properly in your app, or it's conflicting with other libraries. I wrote a post on this yesterday, it's comment #8 on this page
Last edited by RailsRhino (2010-11-21 17:35:55)