Reputation: 93
So I wanna add some new fields to my Devise model User. When I was using Rails 3 I just added new fields to model and added those fields to Model.rb
attr_accessible :name, :etc
and then I changed Registration view. Now I've done the same, but I haven't Devise/User controller so I can't do something like this
def user_params
params.require(:users).permit(:name)
end
Or
attr_accessible :name, :etc
Upvotes: 7
Views: 9304
Reputation: 1793
Since Devise 4, the Parameter Sanitaizer API has changed:
class ApplicationController < ActionController::Base
before_action :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
end
end
Upvotes: 0
Reputation: 1439
There are three parts to this:
rails generate migration add_name_to_users name:string
You need to add the ability to add/edit the name in the registration/edit forms for your user. (which it seems like you've already done in your first code sample)
You need to add the strong params that you added to your controller (which you've already done in your second code sample.
Basically it seems like you haven't generated the migration. Are you getting any error messages?
Upvotes: 0