I am using devise_invitable gem in my rails 5 application. Every time after submitting the "Send an Invitation" button, I get the error RuntimeError in Devise::InvitationsController#create, Could not find a valid mapping for nil
Here is the code of application_controller.rb file:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_action :configure_permitted_parameters, if: :devise_controller?
def authenticate_inviter!
unless current_user.role=='Manager'
if current_user.role == "Developer"
redirect_to root_path, :alert => "Access Denied! Only Manager Can Add New Developer"
end
super
end
end
protected
def configure_permitted_parameters
added_attrs = [ :email, :password, :password_confirmation ]
devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
devise_parameter_sanitizer.permit :account_update, keys: added_attrs
devise_parameter_sanitizer.permit :accept_invitation, keys: [:email]
end
end
Here is the Code of User.rb:
class User < ApplicationRecord
include DeviseInvitable::Inviter
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
Here is Route.rb
Rails.application.routes.draw do
devise_for :users
root 'dashboard#index'
end
Here is all routes:
Prefix Verb URI Pattern Controller#Action new_user_session GET /users/sign_in(.:format) devise/sessions#new user_session POST /users/sign_in(.:format) devise/sessions#create destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy new_user_password GET /users/password/new(.:format) devise/passwords#new edit_user_password GET /users/password/edit(.:format) devise/passwords#edit user_password PATCH /users/password(.:format) devise/passwords#update PUT /users/password(.:format) devise/passwords#update POST /users/password(.:format) devise/passwords#create cancel_user_registration GET /users/cancel(.:format) devise_invitable/registrations#cancel new_user_registration GET /users/sign_up(.:format) devise_invitable/registrations#new edit_user_registration GET /users/edit(.:format) devise_invitable/registrations#edit user_registration PATCH /users(.:format) devise_invitable/registrations#update PUT /users(.:format) devise_invitable/registrations#update DELETE /users(.:format) devise_invitable/registrations#destroy POST /users(.:format) devise_invitable/registrations#create accept_user_invitation GET /users/invitation/accept(.:format) devise/invitations#edit remove_user_invitation GET /users/invitation/remove(.:format) devise/invitations#destroy new_user_invitation GET /users/invitation/new(.:format) devise/invitations#new user_invitation PATCH /users/invitation(.:format) devise/invitations#update PUT /users/invitation(.:format) devise/invitations#update POST /users/invitation(.:format) devise/invitations#create root GET / dashboard#index rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create
- I haven't created any custom invitations controller.
I just run the following to setup and configure devise_invitable
gem 'devise_invitable'
bundle install
rails generate devise_invitable:install
rails generate devise_invitable User
rails db:migrate
rails generate devise_invitable:views
restart the rails server
Here is the picture of the complete error: see the picture of the complete error
How can I get rid of this problem. Please help me