【Elixir】Phoenix で静的ファイルを追加する
【Elixir】Phoenix で静的ファイルを追加する
Elixir Phoenix の環境で静的ファイルを追加する方法
環境
- Elixir 1.14.2
- Phoenix 1.6.3
静的ファイルを追加する
priv/static/にフォルダを追加します。lib/demo_web/endpoint.exに追加したフォルダ名を追加
onlyの箇所にhoge追加
plug Plug.Static,
at: "/",
from: :sdm,
gzip: false,
only: ~w(assets fonts images favicon.ico robots.txt hoge)
Routes.static_pathを使用してテンプレート側で使用する。
<img src={Routes.static_path(@conn, "/hoge/hoge.png")} alt="hoge"/>
これにより画像などの静的ファイルの呼び出しが可能になります。