如何生成devise gem的注册控制器 [英] How to generate Registration controller of devise gem
问题描述
我已经设置了Devise,我已经在我的user.rb文件中设置了以下代码
I have setup Devise, I have set up the below code in my user.rb file
def self.create_auto_password
generated_password = Devise.friendly_token.first(8)
self.create(password: generated_password, password_confirmation: generated_password)
end
然后我尝试通过运行来生成注册控制器
I then tried to generate a registrations controller by running
rails产生devise:controllers -c注册
和其他一些变体,但不会生成...在Devise中创建注册控制器的正确命令是什么?
and a few other variations but it won't generate... what is the correct command to create a registrations controller in Devise?
推荐答案
只需手动创建控制器并使其继承于Devise.例如:
just create the controller manually and make it inherit from Devise. For example:
class Users::RegistrationsController < Devise::RegistrationsController
# Override the action you want here.
end
此控制器应位于app/controllers/users/registrations_controller.rb
This controller should live in app/controllers/users/registrations_controller.rb
并在您的路线中提及它.
And mention it in your routes.
devise_for :users, controllers: { registrations: "users/registrations" }
如果只想通过命令生成它,则不需要从master分支添加设备gem,因为该分支上存在该生成器.
And if you want to only generate it by command than you need to add device gem from master branch because that generator is present on that branch.
gem 'devise', git: 'https://github.com/plataformatec/devise'
这篇关于如何生成devise gem的注册控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!