且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

生成设备控制器-Rails Devise

更新时间:2022-10-14 23:34:46

设计了许多命令提供。


  1. rails generate devise:install -将创建 config / devise.rb

  2. rails generate devise User -将创建 db / migration-file-for-user-model 其中的注释代码,如果需要其他模块,则可以注释。 。例如 confirmable omniauth

  3. rails generate devise:views -将在 devise 文件夹中使用 app / views / devise / sessions创建所有视图 app / views / devise / confirmations registrations etc文件夹及其视图。

  4. rails生成devise:views用户-将创建 app / views / users / passwords / $的文件夹c $ c>, app / views / users / confirmations ..etc而不是上面的 devise 文件夹。

  5. rails generate devise:controllers -将创建所有 controllers .. 类似于上面 ...在此处,它将使用默认的注释代码创建 app / controllers / devise / sessions_controller.rb ,您需要对其进行编辑否则,请保留它以用于基本身份验证。此外,还可以最后添加个用户 作用域,以在 controllers / users / 而不是 controllers / devise /

您也可以阅读这篇很好的 设计教程 > ..



希望有帮助。


I am trying devise for the first time.I am following the link:https://github.com/plataformatec/devise. Here,i have executed the command:

rails generate devise MODEL

when i have executed this,the model and view parts are created.When i checked the routes,I have noticed that there is a controller created with the name:MODEL.but i didnot find the controller in the project.My query is how can we find whether a controller is generated or not and use that controller in the project. Thanks in advance.

There are many commands that devise provides..

  1. rails generate devise:install - will create config/devise.rb
  2. rails generate devise User - will create db/migration-file-for-user-model which commented code,which you can uncomment,if you need other modules..such as confirmable,omniauth etc
  3. rails generate devise:views - will create all views in the devise folder with app/views/devise/sessions,app/views/devise/confirmations,registrations etc folder and its views respectively.
  4. rails generate devise:views users - will create folder of app/views/users/passwords/,app/views/users/confirmations ..etc instead of devise folder above.
  5. rails generate devise:controllers - will create all controllers..similar to above...here it will create app/controllers/devise/sessions_controller.rb with default commented code,which you need to edit else leave it as it is for basic authentication.Moreover,you can also add users scope in the end,to generate controllers in controllers/users/ and not controllers/devise/

You may also go through this good devise tutorial ..

Hope it helps.