Displaying 20 results from an estimated 6000 matches similar to: "[PATCH] add :root option to ActiveModel JSON serialization"
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
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
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
2012 Jun 21
1
ActiveModel::Serializers::JSON support arbitrary keys
Is there a reason why AM:S doesn''t support arbitrary keys to serialization?
I can see a lot of uses cases where arbitrary keys could come handy. Right
now, if one tries to do it, AM:S checks if the keys match a method of the
model and raises exception if it can''t find any.
class Client < ActiveRecordBase
attr_accessible :name, :address, as: :creator
include
2010 Feb 19
0
Problem in ActiveRecord#to_xml
Hi, a couple of days ago I filed a ticket related to a problem with the
to_xml ActiveRecord method. (
https://rails.lighthouseapp.com/projects/8994/tickets/3982-patch-solved-a-bug-that-prevented-xml-serialization-when-activerecord-attributes-contains-more-than-column-values
).
I solved it by making to_xml to infere the type by means of a ruby-xml type
conversion, using a Hash that was already
2011 Feb 05
3
ActiveModel::AttributeMethods limiting
In my attempt to add AM:Dirty to my model I realized that
AM#AttributeMethods is a bit imperfect. It''s impossible to generate
attribute methods step-by-step in DataMapper-like manner.
class Model
include ActiveModel::Dirty
def self.property(name, klass = String)
define_property_accessors(name, klass)
# This method will be called once, because of
2011 Feb 03
0
Correct way to exclude attributes from json serialization
Hi
I''m using Mongoid and Rails 3, and I want to serialize one of my
mongoid documents to json for publishing via a controller, e.g.
class ReportController < ApplicationController
respond_to :json
def show
report = Report.where(:report_id => params[:id]).first
respond_with report
end
end
This works ok, but pushes out every attribute on the document
2010 Nov 01
1
[patch] Allowing to_xml to rename keys in lower camel case format
Hi all,
I''ve created and submitted a patch to resolve an issue I had while
attempting to meet the OpenSocial API specifications, which dictates that
the xml output have tags formatted as lower camelcase (as opposed to upper
camelcase, which is currently the only option). With this patch, simply
passing :camelize => true still begets the current behavior, but you can now
enable lower
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()
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 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 Dec 16
0
MassAssignmentSecurity for multiple contexts
I need to add some mass assignment protection (ala
ActiveModel::MassAssignmentSecurity) but I can''t find how to do it
contextually. For example, in one controller action I want to to
whitelist attributes x, y and z and in another I want to whitelist
attribs y and z. How can I do that? The attr_accessible function has a
class-wide scope, whether in a model or in a controller. But I would
2012 Sep 25
3
Proposal for a new ActiveModel::Errors structure
There are few issues with the current ActiveModel::Errors class.
Firstly, when an error is added to ActiveModel::Errors class via #add
method
(https://github.com/rails/rails/blob/master/activemodel/lib/active_model/errors.rb#L294)
its translation is added. It should not be translated when being added, but
only when being read.
The second issue is a bit bigger. We''d like to create
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 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
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 Oct 16
0
HTML5 Data Attributes
Here''s a proposed patch to simplify HTML5 data attribute declaration:
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5825-html5-data-attributes
Any comments?
As explained in the ticket:
Specifying HTML5 data attributes for tags could be more streamlined.
Right now you would use string keys and repetition.
To create, for example, this:
<div
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
2012 Aug 05
0
ActiveRecord::Validator vs ActiveModel::Validator
I know that there is an ActiveModel Validator class
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/validator.rb
which is used for the class level validation macros.
But I didn''t find a an ActiveRecord Validator class.
From my understanding in Rails 3, validations have been moved into
ActiveModel to leave ActiveRecord as an ORM.
So now I see this Rails 3 code
2010 Aug 13
2
Rails 3 / ActiveModel for Credit Card information?
When submitting billing information in the past I''ve always used
attr_accessor for credit card details as they should not be saved in
the database. In addition I always end up storing the card
expiration date so that the date form helper works correctly.
With Active Model it seems logical to create a CreditCard class to
hold this data instead.
**1st issue.**
It seems there still