0
votes

i am currently trying to sign up/create an account for application using devise on ruby on rails(5.2.2) and ruby version 2.3.7 but i am getting the unpermitted parameter message and tried with Strong parms but it didn't work.

tried this two posts below but didn't work

Rails 4 and Devise: Devise not saving new information (First Name, Last Name, Profile Name)

Rails 4 and Devise: Devise not saving new information (First Name, Last Name, Profile Name)

class Api::V3::ApplicationController < ActionController::Base
  protect_from_forgery with: :null_session
  before_action :configure_permitted_parameters, if: :devise_controller?
  # before_filter :authenticate_user!
  private
  def configure_permitted_parameters
     devise_parameter_sanitizer.permit(:sign_up, keys: [:firstname,:lastname,:username,:password]) 

   # devise_parameter_sanitizer.for(:sign_up) << :provider
   # devise_parameter_sanitizer.for(:sign_up) << :uid
  end

end

Processing by Devise::RegistrationsController#create as JSON
Parameters: {"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "firstname"=>devise", "lastname"=>"test"}} Unpermitted parameters: :firstname, :lastname

it looks like devise is not accepting parameters and which is resulting in first and last name not stored in local database.

1
Did you tried adding :firstname and :lastname in sign_up_params in your devise registration controller? you have to permit those in registration controller...Abhishek Aravindan
@AbhishekAravindan didn't do that how can i access devise registration controller or do i need to create a registration controller that extends devise registration controllerron
rails g devise:controller will generate controllers for you.... or you can add a controller that extends devise registration controllerAbhishek Aravindan

1 Answers

1
votes

You can override the registration controller and add fields you want.

class RegistrationsController < Devise::RegistrationsController

def create
  build_resource(sign_up_params)

if resource.save
  if resource.active_for_authentication?
    set_flash_message :notice, :signed_up if is_navigational_format?
    sign_up(resource_name, resource)
    respond_with resource, :location => after_sign_up_path_for(resource)
  else
    set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
    respond_with resource, :location => after_sign_up_path_for(resource)
  end
else
  clean_up_passwords
  respond_with resource
end
end  
# you will get the full registration controller in devise github repo

 private

def sign_up_params
 params.require(:user).permit(:email, :first_name, :last_name, :password, :password_confirmation)
end

end

and add the new routes too

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

devise github repo here