-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Take 3 - Simplified Complete Solution] A way to use ja_serializer with a vanilla phoenix 1.7.X app - without using the fallback phoenix_view package #5
base: main
Are you sure you want to change the base?
Conversation
@@ -38,7 +38,7 @@ defmodule Example17xAppWeb do | |||
def controller do | |||
quote do | |||
use Phoenix.Controller, | |||
formats: [:html, :json], | |||
formats: [:html, :json, :"json-api"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the mime type in config/config.exs, I appear to be forced to add "json-api" here (because of the dash I need to define it as a stringy atom).
# in the function (as shown below in the show() function). For more details on put_view() usage look under | ||
# the render() documenation at https://hexdocs.pm/phoenix/0.10.0/Phoenix.Controller.html#render/3 | ||
# | ||
plug :put_view, Example17xAppWeb.ThingView |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use phoenix 1.7.X directly (as part of the approach in this PR), we need to use put_view()
as otherwise phoenix 1.7.X will expect a name like Example17xAppWeb.ThingJSON-API
for the view layer module.
(This is because phoenix will try to initially base the name on the :"json-api"
format configured earlier).
@@ -1,5 +1,4 @@ | |||
defmodule Example17xAppWeb.ThingView do | |||
use Example17xAppWeb, :view |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use use Example17xAppWeb, :view
(well, not without creating it) as phoenix has moved away from this idea with the move to phoenix 1.7.X.
Overview
This PR follows on from vt-elixir/ja_serializer#346 (comment) and is an attempt to document a reasonable way of using ja_serializer with phoenix 1.7.7 without using the fallback
phoenix_view
package.With these changes in place the simple test suite passes 🥳
Resources useful for understanding the move from phoenix 1.6.X to 1.7.X