How to serve an img with Phoenix?

Your static assets can be served by using the static_path routes. You’ll want to use src instead of source attribute for the file source for your image. But here’s how it should look:

<img src="<%= static_path(@conn, "/images/crvmlogowhite.svg") %>">

Keep in mind with the default configuration of brunch, your asset files are copied to priv/static/ and are served from there. Your endpoint.ex file defines what static files should be served from that directory.

5 Likes