2017-05-14 12 views
0

フェニックスは、ルーターのルートに関連付けられたURLを生成するためにヘルパーを自動的に生成します。フェニックスルータにルートパスが存在するかどうかを確認する方法

例:

scope "/", Zombie.App, as: :app do 
    pipe_through :browser 

    get "/", PageController, :home # app_page_path() 
    get "/about", ZombieController, :about # app_zombie_path() 
end 

どのように特定のパスヘルパーが自分のアプリケーションに存在するかどうかを知ることができますか?

答えて

0

それは簡単です、あなたが行うことができ、あなたはパスヘルパーapp_zombie_pathは()が存在するかどうかを知りたいとしましょう:私はKernel.function_exported?を使用する

path = :app_zombie_path 
router_paths = Zombie.Router.Helpers.__info__(:functions) 

if Keyword.has_key?(router_paths, path) do 
    # The path exists 
end 
1

iex(3)> if function_exported?(NewAdmin.Router.Helpers, :group_path, 2), do: "yes", else: "no" 
"yes" 
iex(4)> 
+0

もう1つの素晴らしい解決策ですが、アリティを指定する必要があります。 –

関連する問題