3 ms·
To be safe from this in Phoenix that would look like this right? def profile(conn = %{method: "GET"}, params) do # ... end def profile(conn
by nickjj 7y ago
To be safe from this in Phoenix that would look like this right?
def profile(conn = %{method: "GET"}, params) do
# ...
end
def profile(conn = %{method: "POST"}, %{"user" => user_params) do
# ...
end
This would be in a case where your router looks like:
get "/profile", UserController, :profile, as: :user
post "/profile", UserController, :profile, as: :user
That's what I'm doing in my code base at the moment. Mainly thanks to Changelog open sourcing their platform, and you can see that pattern being used here: https://github.com/thechangelog/changelog.com/blob/f9b0a758746f2cec10781b77eb0541cce765e054/lib/changelog_web/controllers/person_controller.ex#L90 https://github.com/thechangelog/changelog.com/blob/f9b0a7587...
The above seems like the natural way to do it with Phoenix once you get a hang of pattern matching.
- griffinmb 7y agoYep, that’s the way!