JSON + Rails + Javascript

Hello Experts,

When i try to use json converstion for Array it works perfectly in local machine,

But when i deployed to server it says this error message which i detected on firebug

I've two datas on DB Model - Codes

Codes 1 - First 2 - Second 3 - Third

Here I have a code like this Controller name = "%#{params[:id]}%" @codes = Code.find(:all, :condition => ["name like ?", name])

on View

<input type="text" id="input_id"> <a href="javascript:void(0);" onclick="filter_this(document.getElementById('input_id'), < %=@codes.to_json%>);">Click Me</a>

and javascript code function filter_this(myInput, codes) {   for(var i=0;i<codes.length;i++) {     var myid = codes[i].attributes;     var filter_divs = 'div' + myid.id;     document.getElementById(filter_divs);   } }

This code works perfectly in local but in server it says myid has no properties.

NOTE: I've included all necessary javascript codes.

Thanks in advance Bala

Hello Experts,

When i try to use json converstion for Array it works perfectly in local machine,

But when i deployed to server it says this error message which i detected on firebug

I've two datas on DB Model - Codes

Codes 1 - First 2 - Second 3 - Third

Here I have a code like this Controller name = "%#{params[:id]}%" @codes = Code.find(:all, :condition => ["name like ?", name])

on View

<input type="text" id="input_id"> <a href="javascript:void(0);" onclick="filter_this(document.getElementById('input_id'), < %=@codes.to_json%>);">Click Me</a>

and javascript code function filter_this(myInput, codes) { for(var i=0;i<codes.length;i++) { var myid = codes[i].attributes; var filter_divs = 'div' + myid.id; document.getElementById(filter_divs); }

}

This code works perfectly in local but in server it says myid has no properties.

I suggest you examine the generated JSON. Firebug also has a javascript debugger you can see what is going on (I suspect the problem is that codes[i] does not have an attributes property. The difference is probably that in production you have a newer version of rails than in development - newer versions of rails add a to_json method to activerecord objects that just dump the attributes)

Fred