Skip to content
This repository has been archived by the owner on Jul 11, 2020. It is now read-only.

read_only attributes not being added to metadata when not using default serializer #11

Open
marktran opened this issue Jan 3, 2015 · 1 comment

Comments

@marktran
Copy link
Contributor

marktran commented Jan 3, 2015

I'm seeing an issue where read_only attributes aren't in the read_only metadata if e.g. I have an EventsController that uses a serializer named BasicEventSerializer (or anything that's not the default EventSerializer).

Looks like it's because RenderJsonMeta::MetadataReadOnly only looks for the default serializer:

serializer = model.try(:active_model_serializer)

class EventsController < APIController
  handles :show

  def show
    render(
      json: self.record = model.find(params[primary_key]),
      serializer: BasicEventSerializer
    )
  end
end
class BasicEventSerializer < ActiveModel::Serializer
  embed :ids

  attributes :id
  read_only :created_at
end
{
  "event": {
    "id": 24522,
    "created_at": "2014-11-24T16:02:08.383Z"
  },
  "meta": {
    "event": {
      "read_only": [],
      "nested_resources": []
    }
  }
}
@marktran
Copy link
Contributor Author

marktran commented Jan 3, 2015

Looks like it might be better to grab the serializer being use from the options hash with the serializer key:

def _render_option_json(resource, options)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant