phasnox
Use Routes.static_path in LiveComponent
Is there a recommended way to use the Routes.static_path in a live component?
I guess I could pass the @conn in the session and then Rotes.static_path(@conn, ...), but was wondering if there is a better way to do this.
Thanks!
Most Liked
sfusato
Path helpers can take the @conn, @socket or even the Endpoint as 1st argument. As for Routes, it’s just a module: alias MyAppWeb.Router.Helpers, as: Routes (you probably have this in your my_app_web.ex file)
jaimeiniesta
Ah, of course that was it! Thanks for the help.
For the record, the alias for Routes is defined like this: https://hexdocs.pm/phoenix_live_view/installation.html#phx-gen-live-support
In my case it wasn’t working because I was using:
use Phoenix.LiveComponent
when I should use:
use MyAppWeb, :live_component
sfusato
You can also pass the Endpoint: Routes.static_path(MyAppWeb.Endpoint, ...)
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








