web / router.ex中嵌套作用域定义的行为

时间:2017-03-15 15:15:41

标签: elixir phoenix-framework

文档根本没有提到这一点。是否允许嵌套作用域定义,如果是,则在web / router.ex中为以下内容定义的行为是什么:

scope "/:locale", MyApp do
  pipe_through [:browser, :locale]

  scope "/auth", MyApp do
    pipe_through [:auth]

    get "/", PageController, :dummy
  end

  get "/", PageController, :dummy
end

管道链,.i.e是/:locale / auth请求路由:browser,:locale AND:auth?任何陷阱?

2 个答案:

答案 0 :(得分:1)

是的,允许范围定义,并且管道由嵌套范围继承。 Phoenix repo contains tests for pipelines in nested scopes断言父作用域中的所有pipe_through都由子作用域中的路由继承。

scope "/browser" do
  pipe_through :browser
  get "/root", SampleController, :index

  scope "/api" do
    pipe_through :api
    get "/root", SampleController, :index
  end
end

# ...

test "invokes pipelines in a nested scope" do
  conn = call(Router, :get, "/browser/api/root")
  assert conn.private[:phoenix_pipelines] == [:browser, :api]
  assert conn.assigns[:stack] == "api"
end

答案 1 :(得分:1)

您将拥有以下路线

MyApp.MyApp.PageController

我觉得您不想实际指向scope "/:locale", MyApp do pipe_through [:browser, :locale] scope "/auth" do pipe_through [:auth] get "/", PageController, :dummy end end ,因此您可以定义scope/2而无需指定别名。

MyApp.PageController

现在只需将您的身份验证路线指向public class CheckBoxRenderer extends JCheckBox implements TableCellRenderer { CheckBoxRenderer() { setHorizontalAlignment(JLabel.CENTER); } public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Object valueInColumn1 = table.getValueAt(row, 1); if (valueInColumn1 == null) { JLabel x=new JLabel(); return x; } setSelected((value != null && ((Boolean) value).booleanValue())); return this; } }