Posted by: khirakawa on: July 21, 2009
Are you getting an RJS error in IE6, that reads “[ Object Error ]“, followed by escaped javascript?
That’s what I was getting last night while I was creating some simple navigation tabs. It was frustrating because it worked in Firefox and Safari, but not IE6. And the error message? Object Error? What does that tell me? Nothing!
So I narrowed down my javascript code to this line:
var tab_1 = document.getElementById("first_tab");
tab_1.removeClassName("active");
This was throwing the error. But why?
Well, it turns out in order to use the Prototype method removeClassName(), the element (in this case, tab_1) must have Prototype DOM extensions.
So how do you get elements with Prototype DOM extensions? Use the dollar method my friend.
Instead of getting the element from getElementById() and then calling removeClassName(), simply do:
$("first_tab").removeClassName("active")
And voila, it works in Firefox, Safari, and IE6.
Posted by: khirakawa on: July 15, 2009
Being a newbie rails developer, there are a number of rails caveats that I wish I knew beforehand, such as this one:
Suppose I have a div with id = “test” and I have a controller function that removes the div using
page[:test].remove
Now suppose I have a functional test as such:
assert_select_rjs :remove, "test"
Well, it happens to be so that this test fails, even though all my other assert_select_rjs assertions succeed. Only when the first argument is :remove does the test fail.
Now I don’t know why this is (anybody want to enlighten me?), but I’ve found a workaround.
Instead of the the code above, do:
assert_equal @response.body, '$("test").remove();'
The assert_select_rjs function supposedly does a similar thing under the hood where it does a regex comparison on the response body.
And there you have it. Test success!