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 ActiveModel::Serializers::JSON
def attributes
{label: name, value: id}
end
While I can easily create a method for all the keys I want to create, take
the example above, where a jquery plugin requires a data structure of
"value: id, label: string". Does it really make sense to create a value and
label method in a model? I can see this becoming cumbersome real fast
(different values for different query).
--
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/-/td2Y13_PRhIJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-core?hl=en.