I was scratching my head over why my application breaks when I run on
a local server but works on my remote server. It turns out that my
local server is Rails 2.0.2 and my remote server is 1.2.3 and I expect
the tag "attributes" to be passed with a json stream, before parsing.
Unfortunately, this was dropped in 2.0.2. Is there any documentation
on this? Any way to get it back?
Rails 2.0 introduced a Json serializer into ActiveRecord that behaves
differently:
http://dev.rubyonrails.org/browser/trunk/activerecord/lib/active_record/
(Check out serialization.rb and serializers/json_serializer.rb)
The AR Serializer extracts serializable methods and attributes and
creates a serializable record out of that which is THEN processed by
ActiveSupports JsonConverter.
To get the old behaviour, use
ActiveSupport::JSON.encode(@record.instance_values)
This looks like it might be related to an issue that I'm having getting
some code from the book "Google Maps Applications with Rails and Ajax".
I am a complete Ruby and Rails beginner, and a fairly rusty coder to
boot, and so have no idea how the suggestion of helps:
But appreciate being pointed in the right direction non the less and
would very much appreciate any further help anyone can give.
Everything is working fine on my dev environment which is running 1.2.6,
but not on my Heroku.com account which is running 2.0.2. The code in
question I believe is as follows:
def list
render :text=>(Marker.find :all).to_json
end
and is later called by a Javascript function where the relevant code is
this:
//tell the request what to do when the state changes.
request.onreadystatechange = function() {
//alert('Step 1');
if (request.readyState == 4) {
//parse the result to JSON, by eval-ing it.
//The response is an array of markers
//alert('Step 2');
markers=eval("(" + request.responseText + ")" );
for (var i = 0; i < markers.length ; i++) {
var marker=markers[i].attributes
//alert(Step 3);
var lat=marker.lat;
var lng=marker.lng;
I get a JavaScript error telling me that 'marker has no properties'
which I think kicks in somewhere around the commented out Step 3 alert.
Failing any solution to the above does anyone know how/if it is possible
to role back to 1.2.6 when already running 2.0.2? This might be best
whislt I'm using two books which are both written for versions of Rails
earlier than 2.0.
Any light that anyone can shed on this would be very very much
appreciated.