gpt4 book ai didi

ruby-on-rails - Rails - 设计 - 向 Controller 添加 Action

转载 作者:行者123 更新时间:2023-12-04 18:43:19 26 4
gpt4 key购买 nike

我在我的设计 Controller 中添加一个 Action 时遇到了一些麻烦。
我创建了一个名为 registrations_controller 的 Controller 在文件夹中 users/像这样:

class Users::RegistrationsController < Devise::RegistrationsController

而且,有我的路线文件:
root to: 'home#index'

devise_for :users
devise_scope :users do
get 'users/profil/:id', to: 'users/registrations#profil', as: 'profil'
end

我看到以下错误:
Unknown action
Could not find devise mapping for path "/users/profil/1"
This may happen for two reasons: 1) You forgot to wrap your route inside the scope block. For example: devise_scope :user do get "/some/route" => "some_devise_controller" end 2) You are testing a Devise controller bypassing the router.

我的代码有什么问题?

最佳答案

请尝试以下操作:

    devise_scope :user do
get 'users/profil/:id', to: 'users/registrations#profil', as: 'profil'
end
devise_for :users, :controllers => {:registrations => "users/registrations"}
resources :users

您也不需要为 Controller 命名 Users::RegistrationsController将其命名为 RegistrationController保持继承不变 Devise::RegistrationsController

关于ruby-on-rails - Rails - 设计 - 向 Controller 添加 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19941106/

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