smpallen99/coherence

Custom url path for controller actions

Open

#292 建立於 2017年10月9日

在 GitHub 查看
 (6 留言) (0 反應) (0 負責人)Elixir (1,259 star) (220 fork)batch import
enhancementhelp wanted

描述

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?

貢獻者指南