New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to use template rather than exposing models fully #27
Comments
Hi filvo, thanks! There isn't a way / plan to use templates at the moment - we purposed strip out rails built in templates. You can write custom serializers (e.g. check out activerecord serializers / write your own DelegateClass-based implementations, you simply need to define There are plans to make this customisable, but it likely wont happen until 2.0. In the mean time, you can check #20 and #23 for some more guidance / ideas. |
I'm new to module RocketPants
module Respondable
private
alias_method :orig_normalise_object, :normalise_object
def normalise_object(json, options = {})
# modified from: https://github.com/josevalim/active_model_serializers/blob/master/lib/action_controller/serialization.rb#L42
if serializer = options.delete(:serializer) || (json.respond_to?(:active_model_serializer) && json.active_model_serializer)
if json.respond_to?(:to_ary)
if options[:root] != false && serializer.root != false
# default root element for arrays is serializer's root or the controller name
# the serializer for an Array is ActiveModel::ArraySerializer
options[:root] ||= serializer.root || controller_name
end
end
options[:scope] = serialization_scope unless options.has_key?(:scope)
options[:url_options] = url_options
serializer.new(json, options.merge(default_serializer_options || {}))
else
orig_normalise_object(json, options)
end
end
end
end
ActiveModel::ArraySerializer.root = false UPDATE: Forgot a few details: Gemfile: Controllers: include ::ActionController::Serialization
def default_serializer_options
{ :root => false }
end I use Mongoid, so I did:
|
Closing this now as 1.6.* is out with it. |
Yo Man! First of all nice work you have done. Is there a way / plans for using templates for response like acts_as_api gem does. I want to use certain records and customized response, not the active records fields.
Thanks
The text was updated successfully, but these errors were encountered: