Custom Devise controller

前端 未结 2 548
一整个雨季
一整个雨季 2020-12-17 00:55

I would like to customize my registrations controller for Devise in Rails. I understand that you must create a controller like this:

class AccountsController         


        
相关标签:
2条回答
  • 2020-12-17 01:35

    As long as you fulfil your required fields you can call Account.create in your example, I'm pretty sure the default Devise required fields are login, password and password_confirmation

    We do this in a CRUD screen for creating devise users,

    @admin = Admin.new(params[:admin])
    if @admin.save
      redirect_to admin_admins_path, :notice => 'New Administrator has been added'
    else
      render :action => "new"
    end
    

    and you don't want to extend the Devise session controller, a normal controller extending ApplicationController is fine or you can extend Devise::RegistrationsController and overwrite the methods you want to tweak in a registrations_controller.rb file

    0 讨论(0)
  • 2020-12-17 01:38

    You can also have a look at the source on Github, if you want to be sure you're overriding things properly, and be sure you're not missing any processing...

    https://github.com/plataformatec/devise/tree/master/app/controllers

    0 讨论(0)
提交回复
热议问题