gpt4 book ai didi

elixir - 如何使用Phoenix框架路由器中的资源更改参数名称

转载 作者:行者123 更新时间:2023-12-03 21:30:32 24 4
gpt4 key购买 nike

有没有办法做到这一点->

resources "users", MyApp.UserController

生成参数名称不是 :id的路径?

最佳答案

resources/4 macro中使用param参数:

resources "users", MyApp.UserController, param: "name"
这将产生以下路线:
  • GET/users =>:index
  • GET/users/new =>:new
  • POST/用户=>:创建
  • GET/users/:name =>:show
  • GET/users/:name/edit =>:edit
  • PATCH/users/:name =>:update
  • PUT/users/:name =>:update
  • DELETE/users/:name =>:delete

  • 以下是资源的其他选项:

    This macro accepts a set of options:

    :only - a list of actions to generate routes for, for example: [:show, :edit]

    :except - a list of actions to exclude generated routes from, for example: [:delete]

    :param - the name of the paramter for this resource, defaults to "id"

    :name - the prefix for this resource. This is used for the named helper and as the prefix for the parameter in nested resources. The default value is automatically derived from the controller name, i.e. UserController will have name "user"

    :as - configures the named helper exclusively

    :singleton - defines routes for a singleton resource that is looked up by the client without referencing an ID. Read below for more information

    关于elixir - 如何使用Phoenix框架路由器中的资源更改参数名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32064273/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com