tfwright

tfwright

With the change away from helpers to verified routes, I’m wondering if/how it is possible to invoke a route without knowing the full path including scopes, which was one of the uses of named helpers?

Showing Posts 1 to 7

josevalim

josevalim

Creator of Elixir

Can you provide an example? Even before, you had to know the name. So if you have some sort of contract, where you were like, give me a module name and it should have this helper, you can still define said contract using functions that returns a verified route (which is just a string anyway),

tfwright

tfwright OP

Sure, I am using the named helper without knowing the rest of the routes here: live_admin/lib/live_admin/view.ex at 5d96eee465ed64dcb90eb616aa55537189beb0e6 · tfwright/live_admin · GitHub

Currently, that returns a path like /admin/my_resource with needing to know about the admin scope in the router the route was defined in. My understanding that the path using verified routes would need to be something like ~p"/admin/#{my_resource}"?

BartOtten

BartOtten

This does not answer the question literally, but might present a solution to the problem you are facing.

Your lib seems to accept a scope as option to the macro so this should be possible to generate using the macro:

def resource_path(resource), do: ~p”/admin/#{resource}”

Then you combine a path-less function call with routes verified at compile time.

ps. if you know the resources during compile time too, you can generate more specific function clauses.

def resource_path(%User{} = resource), do: ~p”/admin/users/#{resource}/show”

def resource_path(%Product{} = resource), do: ~p”/admin/products/#{resource}/show”

tfwright

tfwright OP

True, and that part of the scope I can handle, but it’s also possible that the routes were defined in other scopes above it, and I’m not sure where to get those.

BartOtten

BartOtten

I don’t see how that issue can be solved without some rewriting of your macro. Wonder where José comes up with (or not).

Currently writing a lib which hooks into the Router using _before compilation_ and is able to write helpers using all information known about routes (including resolved nested scope paths). Copied some docs already to this forum, see paragraph Powerful but thin as it includes some pointers where you could look at.

If you pass me your email by PM I can grand you access to the still private repo and you can let it inspire you (or decide that writing an extension is actually easier ;))

tfwright

tfwright OP

I dug around in the phoenix_live_dashboard source, since it is mounted using almost the exact same strategy (because I shamelessly copied it), and it looks like it takes advantage of a function that looks like it was added in 1.7: Phoenix.Router.scoped_path/2

AFAICT it does exactly what I need–it returns the full path to the current scope, so by invoking it inside the macro I can grab and store the prefix to use when building my routes.

tfwright

tfwright OP

And for anyone else that needs to do something similar, I adapted a combination of the LiveDashboard/Phoenix 1.7 helpers to remove the dependency on named helpers from my app without requiring 1.7: Remove router helpers dependency · tfwright/live_admin@56a3149 · GitHub

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews