Make url_helpers available in serializers #480
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is built for 0.9, and is a first-pass at getting Rails'
url_helpers
into the serializers. The current approach is a bit tied to Rails, but makes the helpers directly accessible w/in any instance ofActiveModel::Serializer
. This also works for associations.An idea I have for an alternative approach is to expose the URL helpers via a
urls
method available from serializer instances, rather than mixing theurl_helpers
directly intoActiveModel::Serializer
. This would at least provide a seam for non-Rails apps to implement their own solution, while still relying on aSerializer.urls
API. I could try that here to in a different pull request, if it's desired. Or we could roll with this for now and try that when/if needed.Thoughts?