search for: to_json

Displaying 20 results from an estimated 88 matches for "to_json".

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 y...
2010 Jul 14
3
`stack level too deep` when overwriting `to_json`
I''m using [acts_as_commentable_with_threading](http://github.com/elight/acts_as_commentable_with_threading/), and it worked fine until I tried to overwrite the to_json function to include more details about the associated user. Here''s part of the comment class (which was originally defined in the plugin, but I moved it to the models folder, a move which seems not to affect the error): def to_json(options = {}) { :id => id,...
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 => "{\"attributes\": {\"id\":1,\"uname\": \"aotianlong\"}}" >>...
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...
2011 Apr 17
0
newbie: to_json only/except + association confusion
hi, i want to return to_json with ''only'' and also filtered.so i tried various ways, but none of them are really good: A)#OK , but filter missing format.json { render :json => @project.to_json(:only => [:title ], :include=> { :tasks => {:only=>[:id,:title] } } ) } B)#Not OK > filter do...
2013 Jan 07
0
Simplified to_json method API
Sometimes to_json options feels abusing to me: user.to_json(:only => [:id, :name], :methods => [:something]) I would prefer an API like this instead: user.to_json(:id, :name, :something) What do you think about adding a use case like this to to_json? -- You received this message because you are subscrib...
2009 Jan 21
3
Nested serialization with to_json and to_xml with array and hash element
Title: Nested serialization with to_json and to_xml with array and hash element class Person < ActiveRecord::Base has_one :address has_one :job def office() return "Executive_Suite" end end class Address < ActiveRecord::Base belongs_to :person end class Job < ActiveRecord::Base belongs_to :person has_one...
2007 Oct 04
4
2 more JSON / XML feature parity patches before Rails 2.0
...lization/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 => :name) Currently you can only to_json on a _single_ AR::B instance, but not for lists of them. I''ve a patch at http://dev.rubyonrails.org/ticket/9751 that does this but needs verification and probably more input. The other change, while not as serious, is to get an unambiguou...
2013 Jan 07
0
Simplified to_json usage
Sometimes default json options feels abusing to me: person.to_json(:only => [:id, :name], :methods => [:something]) I would like to be able to call something like this for AR objects person.to_json(:id, :name, :something) What do you think about extending to_json API with this use case? -- You received this message because you are subscribed to the Goog...
2009 Aug 07
0
How to specify ActiveRecord's to_json encoding
Question: Hi, our company is using Ruby 1.8.6 with Rails 2.2.2. Does anyone know we can explicitly specify what encoding to use when calling to_json() or to_xml() methods? Problem: We have some multibyte characters in our database. For example we have a table with a name column that has this French accented e: Café Records. When we serialize this object using ActiveRecord''s to_xml() everything looks fine in the browser. When we ren...
2009 Feb 23
2
to_json problem (Rails2.2.2)
Hi all, i got a record from my project server side database, like this : @user = User.find 1 then i cover @user to json format: @user.to_json the result : "created_at": "2009-01-28T12:29:32Z" what''s the T and Z of created_at field ? but i change Rails 2.2.2 to Rails1.1.6, I got : "created_at": "2009-01-28 12:29:32" this is a bug of the Rails2.2.2 ???...
2007 Mar 24
0
overloading to_json with JSON gem installed causing error
...arser. 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 following error: wrong number of arguments (2 for 0) RAILS_ROOT: script/../config/.. Application Trace | Framework Trace | Full Trace /usr/local/lib/ruby/gems/1.8/gems/json-0.4.3/lib/json.rb:622:in `to_json'' /usr/local/lib/ruby/gems/1.8/gems/json-0.4...
2012 Jan 25
4
serializable_hash and serializable_add_includes
...y the :only option to include nothing but serializable attributes. I''m facing a problem when nested models are ''included'' using the :include option. The :only options for the parent model are also getting sent to the nested model(s). Here''s an example: model1.to_json(:include => model2, :only => [:id]) First serializable_hash gets called for model1 and is passed an options hash with :only set to an array including :id. This makes sense to me since the :only option was specified as a top level options. Next serializable_hash gets called for model2 and i...
2008 Mar 13
4
AJAX slow - to_json responsible?
Hello. I am building full-ajax back-end, which consits of many quite big partials. As the system grows up, performance is problem. After every click, partial is refreshed, if needed. I am now at 0.5 sec / request. I tried to simply disable ajax and the result was quite suprising: the same page is rendered over 2x faster. I update 80% of page in case of ajax. (Please dont tell: dont use ajax when
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 with JSON? Erik --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rub...
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...
2010 Feb 20
1
Advanced use of to_xml and to_json
Hello, I''m working on a Rails app which has a REST API. I manage two formats JSON and XML. Very often to simplify the use if the API, I''m making includes. But when you add params to to_json and to_xml like :only, :except, it''s not only applied on the root object but on all the objects included. Do you know libs or methods to answer to these different problems: * Tell never return a user password in the API * Tell always include a relationship or a method in each user seriali...
2012 Jan 27
2
to_json performance
Originally posted on github, reported to the right place. I would like to open a discussion about how `to_json` and `as_json` operates in Rails from a performance standpoint. I''m using Rails 3.2 but this issue applies to almost all versions of Rails. Our use case presents the challenge in sending out potentially large JSON (or XML, but we''ll focus on JSON rendering here) bodies as a resp...
2010 Apr 05
2
Harmonizing JSON/XML serialization
...ot_in_json, especially if/when it ends up in ActiveResource. However, there is also the issue of how Enumerables are serialized. This ticket would have me believe that it''s a solved issue in Rails 3: https://rails.lighthouseapp.com/projects/8994/tickets/3812-collection-root-for-enumerable-to_json But how is this being taken care of exactly? It seems like, for consistency''s sake, we''d want the structure of JSON serialization to be as close to Hash#from_xml''s output as possible. This is the state of affairs with 3.0.0.beta2 (the last two expressions are the most im...
2007 Dec 27
5
Rails 2.02 dropped JSON attribute tag ?
...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? Examples: Rails 1.2.3: >> Site.find(:first).to_json => "{attributes: {title: \"some bogus title\", location: \"some bogus location\"}}" Rails 2.0.2: >> Site.find(:first).to_json => "{title: \"some bogus title\", location: \"some bogus location\"}" Thanks! -Dave --~--~-----...