Copy & Paste Engineer

【Elixir】Phoenix で静的ファイルを追加する

【Elixir】Phoenix で静的ファイルを追加する

Elixir Phoenix の環境で静的ファイルを追加する方法

環境

静的ファイルを追加する

  1. priv/static/ にフォルダを追加します。
  2. lib/demo_web/endpoint.ex に追加したフォルダ名を追加
  plug Plug.Static,
    at: "/",
    from: :sdm,
    gzip: false,
    only: ~w(assets fonts images favicon.ico robots.txt hoge)
  1. Routes.static_path を使用してテンプレート側で使用する。
    <img src={Routes.static_path(@conn, "/hoge/hoge.png")} alt="hoge"/>

これにより画像などの静的ファイルの呼び出しが可能になります。

参考