phasnox

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

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

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

sfusato

You can also pass the Endpoint: Routes.static_path(MyAppWeb.Endpoint, ...)

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement