Change which struct-key the Phoenix path-helpers use
-#phoenix framework
#elixir
#til
By default the Elixir Phoenix path helpers use the :id key. For example: property_path(conn, :show, property) would turn into /properties/1. If you want to use a different key inside the property use the Phoenix.Param protocol in the schema definition.
defmodule Property do
use Ecto.Schema
import Ecto.Changeset
@derive {Phoenix.Param, key: :identifier} # <--- THIS!
@type t :: %__MODULE__{}
schema "properties" do
field :identifier, :string
field ...
end
end
The @derive {Phoenix.Param, key: :identifier} instructs the path helpers to use the :identifier key. Now the path above would turn into /properties/that_identifier instead.
