Yurii10
Yurii10

Reputation: 93

Add new fields to Devise model. Rails 5

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

Answers (2)

Aboozar Rajabi
Aboozar Rajabi

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

Billy Ferguson
Billy Ferguson

Reputation: 1439

There are three parts to this:

  1. Generate the migration to the table to add the fields to your database schema.

rails generate migration add_name_to_users name:string

  1. 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)

  2. 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

Related Questions