search for: as_json

Displaying 10 results from an estimated 10 matches for "as_json".

Did you mean: vms_json
2012 Sep 28
1
How to Include Associations in #as_json
Hi, Does anyone know how to include nested associations when overriding a model''s #as_json method? Below is my attempt to include direct and nested associations. NOTE: "office" is a direct association, "company" is nested association via "office". I''d like both included in the generated json output. def as_json(options={}) super(:include...
2010 Feb 16
0
as_json and self-referential associations
Hi, I''m using the new(?) as_json methods within a rest api I am working on. However I am not sure how you are supposed to, or whether it is designed to handle multiple variations of association inclusion. For example I have a model using acts_as_tree, so that each instance has children and a parent: class CatalogueCategory <...
2011 Feb 03
0
Correct way to exclude attributes from json serialization
..._id: 54857324987546, // internal mongoid document id report_field_a: 1, report_field_b: 2, etc } I would like to strip this when serializing the report to json, and I would also like any embedded documents to have their _id properties excluded too. I have searched for info on as_json, to_json etc but I''m not sure which is the best practice approach. The closest I can get is: class Report include Mongoid::Document ... def as_json(options = {}) serializable_hash({ :except => :_id }.merge(options)) end end ...and then I need to copy that same as_json defi...
2010 Dec 22
2
Rails - JSON object with an array?
Hello, I''m able to create and send a JSON object like so: @mylist << { :id => item.id, :name => name.id } render :json => { :result => ''success'', :mylist => @mylist } That works great. Problem I''m having now is that I need to include users which can be 1 or users per item. @mylist << {
2012 Oct 01
1
active_model_serializers, more than one level deep of associations, specifying serializers per association
...onsiblity other than the existing circular reference checking that happens already (does it only just check for back reference as I remember seeing vs. keeping track of previously output object_ids? I had to do the latter to avoid them in a previous version of restful_json when I was mutilating as_json)? (Apologies for my continued ineptitude.) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/R2qc60bVHg4J. To post to this group, send ema...
2011 Oct 25
7
additional model attributes
Hi, i have a "place" model with 2 columns (id, name). I''m calling an external api which gives me data to create a new place object. I would like to add the address from the external place to the place object and render it as a json result, without storing it in the database. i don''t get any errors, but the address never shows up within the json output. i''ve
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 response of a API...
2009 Dec 08
0
ActiveSupport 2.3.5 and json 1.2.0 gem
...to use the JSON object directly, *not* as a ActiveSupport backend: >> JSON(:one => 1) NoMethodError: undefined method `[]'' for #<JSON::Ext::Generator::State:0x104b7fac0> from /Users/ian/Projects/foo/vendor/rails/activesupport/lib/active_support/json/encoders/hash.rb:45:in `as_json'' from /Users/ian/Projects/goo/vendor/rails/activesupport/lib/active_support/json/encoders/hash.rb:34:in `to_json'' from /opt/local/lib/ruby/gems/1.8/gems/json-1.2.0/lib/json/common.rb:183:in `generate'' from /opt/local/lib/ruby/gems/1.8/gems/json-1.2.0/lib/json/common.rb...
2011 Aug 17
2
JSON PUT/POST/UPDATE
Hey all... I''m building a RESTful JSON API and I find myself writing this: JSON.parse(request.body.read) ...over and over in every controller action that accepts JSON in the request body (which is a lot of actions). Does rails have a better built-in way to keep the code more DRY? Or should I solve that somehow myself? Thanks, Cainus -- You received this message because you are
2012 Sep 18
4
"best practices" for Rails serving RESTful JSON services for use by AngularJS, Ember.js, etc.
...e associations if you told it to allow that, etc. In other words, accepts_nested_attributes_for is inadequate. What we''ve tried and looked into as a DRY way to using Rails in large part as JSON service provider: * RABL: provides an way to do json views (to replace sending options into as_json/to_json) does not handle incoming JSON to be persisted in a similar way. * ActiveModel::Serializers available now and coming in Rails 4 - similar to RABL in that it does not map incoming JSON to be persisted. * strong_parameters available now and coming in Rails 4 - keeps you from being able to...