So I've been working a bit today on a little side project, one which I think is pretty cool and hopefully you'll think so too. I'll be talking about it in more detail in a later post but for now I'm keeping things close to the vest since I have a tendency to talk about projects so much that I lose interest. I'm a freak that way.
At any rate, I wanted to try out the new RJS templates in Rails 1.1. I've read a bit about them and they definitely look to make things easier when dealing with AJAX and JavaScript. The first piece I did worked flawlessly but the second piece just wouldn't work. All it was supposed to do was update an unordered list with a new list element, no more, no less.
Once it didn't work, I started stripping out parts of the partial template so that all that was left was just a simple list element. Unfortunately, even that didn't work. So I went even simpler, I just created a hello world list element inside of the RJS template. Did that work? No, of course not, which is actually somewhat of a good thing since I would have really been confused.
I took a break for lunch, hoping that something would turn up in my head and sure enough, it did. I came back and checked the id I had for the unordered list. It wasn't there! I had given it a class so I could just some CSS magic but hadn't given it an id so while the partial template was being rendered correctly (I saw this in the developer log), it didn't have any information on where to put that rendered data. A quick addition of the id and everything worked just fine.
I don't really have much advice when dealing with RJS templates other than to watch your logs like a hawk, making sure things are being rendered correctly and also to check your id names, making sure they match with what's in your other templates.
Technorati Tags:
ajax, rubyonrails, rjs