ruby-on-railsdevisedevise-invitable

Devise Invitable controller seems not to be reached?


I installed devise-invitable and using the standard devise-invitable controller (which I didn't generate) it functions properly. However, when I tried generating a custom controller for devise-invitable, I encountered some issues. Please find below the steps I took.

Steps I took to generate the controller

  1. Following the documentation of devise I tried generating the invitations controller via the console which failed:
rails generate devise:controllers users -c=invitations 

Running via Spring preloader in process 64830 
Could not find "invitations_controller.rb" in any of your source paths. Your current source paths are: 
/Users/name/code/name/app/lib/templates/devise/controllers 
/Users/name/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/devise-4.7.0/lib/generators/templates/controllers
  1. When this didn't work, I manually tried implementing:
    • a controller in the folder where all other devise controllers were generated
    • Adding the invitations controller to routes.rb

=> This didn't seem to work either, because I tried breaking the controller to see if it was reached, but it doesn't break.

controllers/users/invitations_controller.rb

class Users::InvitationsController < Devise::InvitationsController
  def new
    @hotel = Hotel.find(params[:park_id])
    @user = User.new
    @user.hotel = @hotel
    text to cause an error message
  end
end

routes.rb

Rails.application.routes.draw do
  devise_for :users, controllers: {
    sessions: 'users/invitations'
  }

Solution

  • The problem is in your routes since an invitation is not an session.

    If you changes sessions to invitations in your routes then it will hit the users/invitations controller.

    # routes.rb
    Rails.application.routes.draw do
      devise_for :users, controllers: {
        invitations: 'users/invitations'
      }
    end