为什么 rails 资源不生成编辑路径和新路径?

Why does rails resource not generate edit and new paths?

我有一个 PasswordsController 来处理密码恢复,我想将其作为单一资源进行路由。

来自路由器的代码:

resource :password

我想使用生成的路由如下:

/password/new    # User enters email
/password/create # Send email with link to password edit form with token
/password/edit   # User edits password
/password/update # Password is changed

但由于某些原因 rails 只生成以下路由:

password GET    /password(.:format) passwords#show
         PATCH  /password(.:format) passwords#update
         PUT    /password(.:format) passwords#update
         DELETE /password(.:format) passwords#destroy
         POST   /password(.:format) passwords#create

根据文档,还应该有一个 edit 路径和一个 new 路径。

他们为什么不见了?

(这是 rails 5.2.1.1)

编辑:如评论中所述,问题一定出在我的应用程序配置中的某处,因为使用干净的 rails 应用程序无法重现此问题。

您似乎有一个 api_only 应用程序。 在那种情况下 Rails 省略编辑和新路径。 参见:https://github.com/rails/rails/blob/fc5dd0b85189811062c85520fd70de8389b55aeb/actionpack/lib/action_dispatch/routing/mapper.rb#L1230