# Rails 2.0 Breaks Javascript?

**URL:** <https://www.ruby-forum.com/t/rails-2-0-breaks-javascript/125777>\
**Category:** Rails\
**Created:** [January 11, 2008, 11:18pm UTC](https://www.ruby-forum.com/t/rails-2-0-breaks-javascript/125777 "2008-01-11T23:18:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [January 11, 2008, 11:18pm UTC](https://www.ruby-forum.com/t/rails-2-0-breaks-javascript/125777/1 "2008-01-11T23:18:46Z")

</div>

I have a Rails app frozen to v1.2.5 with a Java Script ticker that  
rotates through news article headlines. It works just fine.

I am porting my app to Rails 2.0, and have implemented the Java Script  
ticker EXACTLY as I did before, but now I get a Javascript error in my  
browser.

I can’t think of anything that has changed to cause this problem  
except for the Rails environment.

Any ideas?

P.S.  
If you need to see any of my code, let me know.

---

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [January 11, 2008, 11:32pm UTC](https://www.ruby-forum.com/t/rails-2-0-breaks-javascript/125777/2 "2008-01-11T23:32:15Z")

</div>

We’ll need to see the javascript ticker code.

Jason

---

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [January 11, 2008, 11:42pm UTC](https://www.ruby-forum.com/t/rails-2-0-breaks-javascript/125777/3 "2008-01-11T23:42:13Z")

</div>

Here it is. The error occurs in the ticker.prototype.rotatemsg  
function. (Exact error message is “this.items[this.pointer].attributes  
has no properties” on line 44.)

// -------------------------------------------------------------------  
// Main Ticker Object function  
// ticker(items, tagId, delay, optionalswitch)  
// -------------------------------------------------------------------

function ticker (items, tagId, delay, optionalswitch) {  
this.items = eval(items); // List of things to cycle through  
this.tickerId = tagId; // ID of ticker div to display information  
this.delay = delay; // Delay between msg change, in miliseconds.  
this.logicswitch = (typeof optionalswitch != “undefined”) ?  
optionalswitch : -1;  
this.mouseoverBool = 0; // Boolean to indicate whether mouse is  
currently over ticker (and pause it if it is)  
this.pointer = 0;  
// var tickerDiv = document.getElementById(this.tickerId);  
// tickerDiv.innerHTML = “Initializing ticker…”;  
this.initialize();  
}

// -------------------------------------------------------------------  
// initialize()- Initialize ticker method.  
// -Gets contents and parse it using JavaScript DOM methods  
// -------------------------------------------------------------------

ticker.prototype.initialize = function () {  
if (this.items.length == 0) { // if no articles found in returned  
content  
document.getElementById(this.tickerId).innerHTML = “Sorry, there are  
no articles to display.”;  
return;  
}  
var instanceOfTicker = this;  
document.getElementById(this.tickerId).onmouseover = function ()  
{instanceOfTicker.mouseoverBool = 1}  
document.getElementById(this.tickerId).onmouseout = function ()  
{instanceOfTicker.mouseoverBool = 0}  
this.rotatemsg();  
}

// -------------------------------------------------------------------  
// rotatemsg()- Rotate through messages and displays them  
// -------------------------------------------------------------------

ticker.prototype.rotatemsg = function () {  
var instanceOfTicker = this;  
if (this.mouseoverBool == 1) { //if mouse is currently over ticker,  
do nothing (pause it)  
setTimeout(function () {instanceOfTicker.rotatemsg()}, 100);  
} else {  
var tickerDiv = document.getElementById(this.tickerId);  
var tickerContent = ‘[’ +  
this.items[this.pointer].attributes.title + ‘](https://www.ruby-forum.com/articles/'%20+%0Athis.items[this.pointer].attributes.id%20+%20')’;  
tickerDiv.innerHTML = tickerContent;  
this.pointer = (this.pointer \< this.items.length - 1) ? this.pointer

- 1 : 0;  
setTimeout(function () {instanceOfTicker.rotatemsg()}, this.delay)  
//  
update container every second  
}  
}

Thanks for helping me ferret this out.

---

<div class="post-metadata">

**Author:** ![partydrone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a6a055/32.png) [@partydrone](https://www.ruby-forum.com/u/partydrone)\
**Post date:** [January 11, 2008, 11:51pm UTC](https://www.ruby-forum.com/t/rails-2-0-breaks-javascript/125777/4 "2008-01-11T23:51:02Z")

</div>

OK, as weird as it is, I removed “attributes” from  
this.items[this.pointer].attributes.id and it works.

Thanks a ton for your time, though. I apologize for not catching this.
