0

I'm using devise_token_authentication gem to build token based authentication rails api, then after that I added some extra fields to Vendor model through different migration, and in order to permit them I wrote this:

class ApplicationController < ActionController::Base    
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, :tax_number])
    devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :tax_number])
  end
end

Then after that I added another model Customer rails g devise_token_auth:install Customer auth

then in routes.rb

Rails.application.routes.draw do
  mount_devise_token_auth_for 'Vendor', at: 'vendor/auth'
  mount_devise_token_auth_for 'Customer', at: 'customer/auth'
end

each time I try to sign_up with customers through 'localhost:3000/customer/auth' I got error message: ActiveModel::UnknownAttributeError: unknown attribute 'tax_number' for Customer.

So is there any way to permit the extra fields only for Vendor model and skip 'Customer' ?

MEH
  • 1,777
  • 3
  • 15
  • 34

1 Answers1

1

look on this setup for multiple devise user models.

or

If you override the RegistrationsController you need to permit extra params directly in registrationsController

class Users::RegistrationsController < DeviseTokenAuth::RegistrationsController
  def create

  end

  def account_update

  end

  private


  def sign_up_params
    params.require(:user).permit(:email, :password, :password_confirmation, :first_name, :last_name, :tax_number)
  end
end
MEH
  • 1,777
  • 3
  • 15
  • 34