Skip to content
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

Make url_helpers available in serializers #480

Closed
wants to merge 1 commit into from

Conversation

stevenharman
Copy link

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 of ActiveModel::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 the url_helpers directly into ActiveModel::Serializer. This would at least provide a seam for non-Rails apps to implement their own solution, while still relying on a Serializer.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?

@stevenharman
Copy link
Author

The Travis failures are on Ruby 2.1.0, and look to be due to a Bundler bug, which has been fixed in Bundler 1.5.1, but Travis is still running 1.5.0.

@stevenharman
Copy link
Author

@spastorino after rebasing on your latest changes for embedding, these tests suddenly fail. I'm pulling my hair out trying to figure out why... can you take a look and see if you spot something?

@spastorino
Copy link
Contributor

👍 will check this as soon as I can. We have a long list to finish before so please hold on with this one. Thanks for the work BTW :)

@stevenharman
Copy link
Author

@spastorino Figured it out; a bug with passing options to associations. Fixed in #483.

@spastorino
Copy link
Contributor

@stevenharman 👍 let me think about all this

@stevenharman
Copy link
Author

The more I think about it, and considering the goal not wanting to be tied to Rails, I prefer the alternative approach in #481 to this one. That said, both still need some work, so if you like one or the other, let me know and I'll focus on polishing them up (and making sure the work with latest master).

This technique ties this usage to Rails, which but makes the helpers
directly accessible w/in any instance of ActiveModel::Serializer,
including any associations.
@steveklabnik
Copy link
Contributor

I'd be interested in either one, and there's also one other open PR to add url support... I think I'd prefer the alternative, too, so let's close this.

@olivierlacan
Copy link

@stevenharman This is pretty great. Any chance I can help you resurrect this?

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

Successfully merging this pull request may close these issues.

4 participants