Skip to content

Commit

Permalink
Update docs for Phoenix.Param
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinschweikert authored Sep 3, 2024
1 parent 19b68e1 commit e1fb084
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/phoenix/param.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ defprotocol Phoenix.Param do
@moduledoc """
A protocol that converts data structures into URL parameters.
This protocol is used by URL helpers and other parts of the
This protocol is used by URL helpers, `Phoenix.VerifiedRoutes` and other parts of the
Phoenix stack. For example, when you write:
user_path(conn, :edit, @user)
~p"/user/edit/#{@user}"

Check warning on line 8 in lib/phoenix/param.ex

View workflow job for this annotation

GitHub Actions / mix test (OTP 24.3 | Elixir 1.11.4)

undefined module attribute @user, please remove access to @user or explicitly set it before access

Check warning on line 8 in lib/phoenix/param.ex

View workflow job for this annotation

GitHub Actions / mix test (OTP 24.3 | Elixir 1.12.3)

undefined module attribute @user, please remove access to @user or explicitly set it before access

Check warning on line 8 in lib/phoenix/param.ex

View workflow job for this annotation

GitHub Actions / mix test (OTP 25.3.2.9 | Elixir 1.14.5)

undefined module attribute @user, please remove access to @user or explicitly set it before access
Phoenix knows how to extract the `:id` from `@user` thanks
to this protocol.
Expand All @@ -19,7 +19,13 @@ defprotocol Phoenix.Param do
## Custom parameters
In order to customize the parameter for any struct,
one can simply implement this protocol.
one can simply implement this protocol. For example for a `Date` struct:
defimpl Phoenix.Param, for: Date do
def to_param(date) do
Date.to_string(date)
end
end
However, for convenience, this protocol can also be
derivable. For example:
Expand Down

0 comments on commit e1fb084

Please sign in to comment.