smpallen99/coherence

Custom url path for controller actions

Open

#292 aperta il 9 ott 2017

Vedi su GitHub
 (6 commenti) (0 reazioni) (0 assegnatari)Elixir (220 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (1259 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

The issue: when developing in phoenix (phx) we want to have a custom path for our Coherence resources. But we currently can't.

In the current file lib/router.ex the resource paths are hardcoded, instead we can have them as default arguments to that they can be customized in each project.

For example:

defmodule Coherence.Router do
...
defmacro coherence_routes(mode \\ [], opts \\ []) do # <--- we have an opportunity here
  ....
  if Coherence.Config.has_action?(:registerable, :new) do
    get "/registrations/new", Coherence.RegistrationController, :new
  end

# And we use this macro in our Phx router as: 
coherence_routes()

While we could do something like this:

defmodule Coherence.Router do
...
defmacro coherence_routes(mode \\ [], opts \\ [:registrations_path: "registrations", ...]) do 
  ....
  if Coherence.Config.has_action?(:registerable, :new) do
    get "/#{opts[:registrations_path]}/new", Coherence.RegistrationController, :new
  end

# And we use this macro in our Phx router as: 
coherence_routes([], [:registrations_path: "accounts"])

I could prepare and open a PR to address that 👍 What do you think?

Guida contributor