Displaying 20 results from an estimated 20000 matches similar to: "How does Rails respond to Ajax with JSON?"
2007 Mar 24
0
overloading to_json with JSON gem installed causing error
I installed the JSON gem because I wanted the JSON parser.
Before installing the JSON gem, overloading worked fine. Before I
remove it, I''d like to see if anyone has an idea of what is going on.
It''s the only JSON parser I''m aware of, so it would be a bummer if it
didn''t work.
After installing, if I overload the to_json method in the class, it
gives me the
2010 Apr 05
2
Harmonizing JSON/XML serialization
The way Rails handles root nodes in JSON and XML serialization is
inconsistent. This has been discussed before:
https://rails.lighthouseapp.com/projects/8994/tickets/2584-232-activeresource-json-doesnt-send-parameters-with-root-node
This seems mostly taken care of with
ActiveModel::Base.include_root_in_json, especially if/when it ends up
in ActiveResource. However, there is also the issue of how
2009 Dec 08
0
ActiveSupport 2.3.5 and json 1.2.0 gem
Hey,
I''ve tried every trick I can find, yet I''m still unable to get the
json gem and ActiveSupport to play nice.
No matter in which order I load json and active support, I still end
up with: NoMethodError: undefined method `[]'' for
#<JSON::Ext::Generator::State:0x104b7fac0>
I''m trying to use the JSON object directly, *not* as a ActiveSupport backend:
2007 Dec 27
5
Rails 2.02 dropped JSON attribute tag ?
Hey there
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?
2006 May 27
5
ActiveSupport JSON working?
Hi,
I am trying to convert a hash to JSON using ActiveSupports built in
.to_json. I am doing similar to the example below but are there
certain strings that could go in place of ''bar'' or ''rez'' that will
break the to_json method? I am using a very long string from rjs
output in place of ''bar''.
Perhaps .to_json is not ready yet?
Thanks,
Peter
2007 Oct 04
4
2 more JSON / XML feature parity patches before Rails 2.0
I''d really like to see just 2 more functional changes to the JSON
serialization/encoding before we get to Rails 2.0.
First, and I think this is really crucial because without it all the
efforts to output JSON from ActiveRecord objects would have been half
in vain, is to allow us to do this in controllers:
@authors = Author.find(:all)
render :json => @authors.to_json(:only =>
2010 Jun 08
8
rails, ajax, json, and script
Could someone please demonstrate the code to send both json (or xml) AND
javascript (to be executed) in a single Ajax request?
Is this even possible?
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
2007 Mar 28
7
Rails, REST and JSON
Hi everyone,
I''m writing a lightweight AJAX application using Rails on the server side as
a RESTful web service provider.
I need the web service to support both JSON and XML I/O. Outputting data in
XML and JSON is easy (using to_xml and to_json),
and it''s also easy to do XML input as Rails does it for you automatically.
Is it possible to somehow have the same
automatic parsing
2009 Jun 14
3
Basic AJAX Response (Mootools)
Hi,
I''ve done AJAX calls to Rails'' Controllers before yet never required to
generate a response back to the view. In this respect, I have tried to
keep it moronically simple and just add a node to see that it works, yet
the response doesn''t come through / isn''t interpreted as it should. Long
story short, code :
// Have to use Mootools to integrate a
2008 Jul 12
0
to_json in Rails 2.0.2 not generating proper json?
I am using Rails 2.0.2 and trying to use to_json to generate json. I
notice several problems.
1) datetime field such as created_at mapped to "created_at": {}
2) :except does not work, @post.to_json(:except =>
[:created_at, :updated_at] still gives me "created_at": {},
"update_at": {}
3) problem with escaped char mapping: ''<'' mapped to
2008 Nov 20
0
pass json data into javascript
Hello from a Ruby on Rails beginner!
I''ve been trying to pass some data to a variable in Javascript by using
json. Seems like the Javascript variable doesn''t receive the data
correctly.
This is the code in controller. @courses variable find the data from
database.
class CoursesController < ApplicationController
def index
@courses = Course.find(:all)
end
end
This
2007 Dec 22
1
Ajax.Updater and JavaScript functions
Hello all,
I have a script that uses a Ajax.Updater call to update the contents
of a DIV. The code being inserted includes a javascript function,
which is "called" by onClick event elsewhere in the HTML.
The page initially works fine in that the DIV gets the right content,
the Javascript inserted works fine.
The problem I have is that if I call the Ajax.Updater again then the
2008 Feb 05
0
prototype-1.6.0.2 Newbie Why is AJAX.request fired 3 times?
Hello list!
I am taking my first steps with AJAX and decided to give prototype a
try.
- I add a reference to the script to my page
- Then somewhere near the bottom of the page I fire up:
new Ajax.Request(''ws_adrestype.php'', {
method:''get'',
requestHeaders: {Accept: ''application/json''},
onSuccess:
2007 Sep 28
2
Rails shouldn't output invalid JSON by default
Please check out this ticket (which would explain almost everything):
http://dev.rubyonrails.org/ticket/8762
So basically, Rails to_json methods produces invalid JSON out of the
box as it doesn''t quote all hash keys. This is valid JSON:
{
"id": 6589,
"code": "SIN",
"name": "Singapore"
}
This is not (Rails'' JSON encoders
2007 Oct 24
0
2 more quick JSON-related patches
Just some quick cleanup and documentation.
Remove obsolete ActiveSupport::JSON::Variable - http://dev.rubyonrails.org/ticket/9969
Add documentation for Hash#to_json and Enumerable#to_json -
http://dev.rubyonrails.org/ticket/9970
Please review :) Thanks!
Cheers,
Chu Yeow
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
2011 Aug 25
7
How to safely embed JSON object in HTML document
Hi all,
I''m working on a Backbone.js single page app with Rails 3.1, and in an
attempt to save on HTTP requests, I want to embed initial data set in
a HTML document that is sent back to the browser after successful
login.
I was thinking I can simply convert my ruby object to JSON, then HTML
escape resulting string of JSON, and then use that as a value for
JavaScript variable. Something
2007 Aug 07
2
"badly formed JSON" exception
I tried to implement the "Rendering JSON in actions" example from
http://wiki.rubyonrails.com/rails/pages/HowtoGenerateJSON :
@headers["Content-Type"] = "text/plain; charset=utf-8"
data = { :foo => ''bar'', :etc => ''rez'' }
render :text => data.to_json
When I try to decode this in javascript with
2010 Aug 03
0
curl works when testing JSON response but the functional and integration tests do not work.
I am trying to test an action which is supposed to give a json
response The url goes something line /blah/model.json
When I POST to that URL using curl like this
curl -H "Content-Type:application/json" -H "Accept:appn/json" -d
"data" http://localhost:3000/blah/model.json it works just fine.
In my test functional test I have this method
def post_json (data)
2007 Dec 11
0
help for hash.to_json
hi , all
under rails 2.0
aotianlong@aotianlong:~/workspace/killer$ ruby script/console
Loading development environment (Rails 2.0.1)
>> {:user=>"aotianlong"}.to_json
=> "{\"user\": \"aotianlong\"}"
>> user = User.find :first
=> #<User id: 1, uname: "aotianlong">
>> user.to_json
=>
2007 Oct 23
2
to_json inconsistency?
Hello,
ActiveSupport::JSON::Variable.to_json is the only to_json without an
"options" parameter. Is this intended?
For example, this code in a .rjs
page[@user.dom_id].visual_effect :drop_out, :afterFinish =>
ActiveSupport::JSON::Variable.new("foo")
fails with
ActionView::TemplateError: wrong number of arguments (1 for 0)
On line #7 of