gpt4 book ai didi

ruby-on-rails - 如何生成设计 gem 的注册 Controller

转载 作者:行者123 更新时间:2023-12-02 00:52:40 25 4
gpt4 key购买 nike

我已经设置了 Devise,我已经在我的 user.rb 文件中设置了以下代码

  def self.create_auto_password
generated_password = Devise.friendly_token.first(8)
self.create(password: generated_password, password_confirmation: generated_password)
end

然后我尝试通过运行生成一个注册 Controller

rails generate devise:controllers -c registrations

和其他一些变体,但它不会生成...在 Devise 中创建注册 Controller 的正确命令是什么?

最佳答案

只需手动创建 Controller 并使其继承自 Devise。例如:

class Users::RegistrationsController < Devise::RegistrationsController
# Override the action you want here.
end

这个 Controller 应该存在于 app/controllers/users/registrations_controller.rb

并在您的 route 提及它。

devise_for :users, controllers: { registrations: "users/registrations" }

如果您只想通过命令生成它,那么您需要从 master 分支添加设备 gem,因为该生成器存在于该分支上。

gem 'devise', git: 'https://github.com/plataformatec/devise'

github_issue 中所述

关于ruby-on-rails - 如何生成设计 gem 的注册 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38477023/

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