Adding extra registration fields with Devise

前端 未结 8 625
情话喂你
情话喂你 2020-12-01 06:57

I am trying to add some extra fields to registrations#new. Since I only want extra data and do not need different functionality, I don\'t see why I need to override controll

8条回答
  •  萌比男神i
    2020-12-01 07:16

    First: Isn't there a new 'strong parameters' issue with rails 4, you might want to look into this as well.

    If you migrate the new parameters into your User model. Then all you have to do is to override (create) the files:

    app/views/devise/registrations/edit.html.erb
    app/views/devise/registrations/new.html.erb
    

    you can look at the default files here: https://github.com/plataformatec/devise/tree/master/app/views/devise/registrations

    IF you might want to implement an own registrations_controller.rb (with actions new and edit) and your own @variables then it is important to add this in your routes.rb

    devise_for :users, :controllers => { :registrations => 'registrations' }
    resources :users
    

    This ensures, that devise takes your new 'registrations' controller from now on (if you decided to have one).

    I don't know "sanitizer" or what this is good for. But my App works just fine with those minor changes I just recommended to you. You don't need to override the Controller! Overriding the Views will just be enough.

提交回复
热议问题