similar to: How to specify ActiveRecord's to_json encoding

Displaying 20 results from an estimated 6000 matches similar to: "How to specify ActiveRecord's to_json encoding"

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 :paygrade def Title return "Engineer" end end
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
2009 Oct 05
0
ActiveRecord Polymorphic Inheritance
I am using RoR ActiveRecord polymorphic inheritance and was wondering if it''s possible to access the base class'' association methods in the invocation of either to_xml or to_json without having to depict the base class data in the serialized string. Here are my classes: # base class class Asset < ActiveRecord::Base belongs_to :resource, :polymorphic => true
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
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 =>
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 does not work, format.json { render :json => @project.to_json(:only
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
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 subscribed to the Google Groups "Ruby on Rails: Core" group. To view this
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
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 Google Groups "Ruby on Rails:
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
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
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
2010 Jul 17
1
not able to find to_yaml definition
I am looking at rails edge source code. I am able to do puts User.find.to_yaml However I am not able to find piece of code where ''def to_yaml'' is. How this to_yaml serialization is working? can fully understand how to_json and to_xml is working but to_yaml beats me. Thanks -- You received this message because you are subscribed to the Google Groups "Ruby on Rails:
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":
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)
2010 Dec 14
9
UTF-8 String.strip bug (and several over methods)
Hello, with Rails 3.0.3 "Café Noir ".strip => "Café noir" but "Café ".strip => "Caf\303\251" In fact, strip() doesn''t works if the last printable character is accentuated. Surprisingly " écologie".strip works fine. I''ve tried to dig deeper in active_support multibyte source code but didn''t found any solution.
2007 Oct 01
0
Patch review requested: #9750 Unambiguous Time, Date and DateTime #to_json format
This patch changes the date format for Time, Date and DateTime #to_json from the ambiguous 10/01/2007 ...to the unambiguous 2007/10/01 http://dev.rubyonrails.org/ticket/9750 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" 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
2010 May 01
0
Add custom root option to AR JSON Serializer
Hi, In short: I can do following: user.to_xml(:root => "xml_user" ) But not following: user.to_json(:root => "json_user") JSON serializer for AR doesn''t allow us to specify "root" option unlike XML serializer. JSON serializer always uses model name as the root if class attribute include_root_in_json is set to true. I''ve added a patch which