Dotol
Dotol

Reputation: 406

Rails Devise/Invitable

I have a Rails app with devise and devise_invitable (links to official docs on overriding controllers), I have made a devise_invitable invitations_controller.rb to display a list of currently invited users within devise/invitations/new.html.erb. Both devise and devise_invitable views are in app/views/devise and app/views/devise/invitations respectively and my devise/devise_invitable controllers are in app/controllers/users/. Rails throws an undefined method 'each' for NilClass in the invitations/new view in my loop:

# app/views/devise/invitations/new.html.erb
<% @invited_users.each do |invited| %>
  omitting code...
<% end %>

# app/controllers/users/invitations_controller.rb
class Users::InvitationsController < Devise::InvitationsController
  def new
    super
    # This is not empty, returns multiple records in console
    @invited_users = User.where.not(invitation_sent_at: nil)
  end
end

# config/routes.rb
...
devise_for :users, controllers: { registrations: 'users/registrations', 
                                  invitations: 'users/invitations' }   
...
end

The weird thing is that when I change the app/views/devise folder name to app/views/users, the error is gone and it displays current invited users but this creates a larger problem which is that the app now uses both devises/devise_invitable's default views.

Upvotes: 0

Views: 161

Answers (1)

Dotol
Dotol

Reputation: 406

Turns out that the culprit was my super statement, the render was being called so it never actually got to the @invited_users, I just moved it below

Upvotes: 0

Related Questions