I would like to have my Custom Active Model Serializer optionally include
an object based on arguments I pass it.

How would I go about doing this w/o having to write a sep Serializer.



class WidgetSerializer < ActiveModel::Serializer
  attributes :id, :name, :sub_widget

  def sub_widget

    # total guess, just an example

    if(sub_widget_option)

      object.sub_widget

    end

  end
  has_one sub_widget
end


class WidgetController < ActionController::Base

  def index
    @widgets = Widget.all()
    render :json=>@widgets, each_serializer:
WidgetSerializer(sub_widget_option: true)
  end

end

-- 
-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
--- 
You received this message because you are subscribed to the Google Groups "SD 
Ruby" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to