gpt4 book ai didi

ruby-on-rails - 添加新操作以设计registrations_controller

转载 作者:行者123 更新时间:2023-12-03 13:45:43 26 4
gpt4 key购买 nike

我的主要设计路线是:

devise_for :accounts,  :controllers => { :registrations => "users/accounts/registrations", :sessions => "accounts/devise/sessions" }, :class_name => 'Admin' 

然后我想要一个新的 url/action,所以我在上面的 devise_for 行之前添加以下内容:
match '/accounts/signedup/' => 'users/accounts/registrations#signedup':

然后在 Controller 中我有注册操作,但是当我去 myurl.com/accounts/signedup 时,目前只有:
def signedup
Rails.logger.debug { "&& signed_up" }
end

然后我去 myurl.com/accounts/signedup 我得到:
AbstractController::ActionNotFound (AbstractController::ActionNotFound):

但是,如果我从 Controller 中删除 def 注册,我会得到:
The action 'signedup' could not be found for Users::Accounts::RegistrationsController"

知道有什么问题吗?

最佳答案

您的回答是正确的,但最新版本的设计已弃用此行为:

Passing a block to devise_for is deprecated. Please remove the block from devise_for (only the block, the call to devise_for must still exist) and call devise_scope :user do ... end with the block instead.



从您发布的内容来看,在您的情况下,您可能应该使用 after_sign_in_path_for在您的自定义 RegistrationsController 中。

这是我在项目中使用的替代方法:
  devise_scope :user do
get 'session/on_signin', :to => 'sessions#memorize_session'
end

关于ruby-on-rails - 添加新操作以设计registrations_controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4821126/

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