Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Elixir 如何使用phoenix后端从elm的静态资产中获取图像?_Elixir_Phoenix Framework - Fatal编程技术网

Elixir 如何使用phoenix后端从elm的静态资产中获取图像?

Elixir 如何使用phoenix后端从elm的静态资产中获取图像?,elixir,phoenix-framework,Elixir,Phoenix Framework,来自elm前端的图像需要存储在静态/图像中的图像: background : Model -> Html Msg background model = img [ src "assets/static/images/main_bg.jpg)" ] [] 我尝试过使用priv/static/images/main_bg.jpg,但得到了相同的错误: ** (Phoenix.Router.NoRouteError) no route

来自elm前端的图像需要存储在静态/图像中的图像:

background : Model -> Html Msg
background model =
    img
        [ src "assets/static/images/main_bg.jpg)"
        ]
        []
我尝试过使用
priv/static/images/main_bg.jpg
,但得到了相同的错误:

 ** (Phoenix.Router.NoRouteError) no route found for GET /assets/static/images/main_bg.jpg (PlatformWeb.Router)
    (platform) lib/phoenix/router.ex:324: PlatformWeb.Router.call/2
    (platform) lib/platform_web/endpoint.ex:1: PlatformWeb.Endpoint.plug_builder_call/2
    (platform) lib/plug/debugger.ex:122: PlatformWeb.Endpoint."call (overridable 3)"/2
    (platform) lib/platform_web/endpoint.ex:1: PlatformWeb.Endpoint.call/2
    (phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:42: Phoenix.Endpoint.Cowboy2Handler.init/4

您正在向端点发出
GET
请求
/assets/static/images/main_bg.jpg
,但没有为其定义路由

如果您想提供
images
文件夹的内容(即
priv/static/images/main\u bg.jpg
),您可以在Phoenix端点中使用(
lib/my\u app\u web/Endpoint.ex

如果要指定要提供的确切内容,请确保将图像添加到
:only
选项中:

defmodule MyApp.Endpoint do
  use Phoenix.Endpoint, otp_app: :my_app

  # Serve at "/" the static files from "priv/static" directory.
  #
  # You should set gzip to true if you are running phx.digest
  # when deploying your static files in production.
  plug Plug.Static,
    at: "/",
    from: :my_app,
    gzip: true,
    only: ~w(images asset-manifest.json manifest.json)

最后,别忘了将您的图像src更改为
“images/main_bg.jpg”

您能告诉我们应该为/assets服务的路由定义以及文件是否存在吗?默认位置是
/images/main_bg.jpg
。不过,根据您的配置,我可能会有所不同。
/images/main\u bg.jpg
给出了相同的结果。至于路线定义,我不确定它在哪里。为了设置elm关系,我在模板中设置了一个div id,作为
/assets/js/app.js
中的一个节点,使用
/elm import{elm}from../elm/src/Main.elm“elm.Main.init({node:document.getElementById(“elm container”)})