I have the following two methods in my CommandsController
class CommandsController < ApplicationController
.
.
.
def userslist
@command = Command.find_by(id: params[:id])
@users_list = @command.users.paginate(page: params[:page], per_page: 10)
end
def deleteuser
user = User.find_by(id: params[:id])
user.commands.destroy(@command)
flash[:success] = "Utente eliminato dalla lista con successo"
redirect_to list_path(@command)
end
.
.
.
end
When I execute deleteuser method I receive the following error:
Command(#31369720) expected, got NilClass(#19349600)
related to line user.commands.destroy(@command)
which means that @command is nil, but why is it so? Isn't @command an instance variable visible by all methods in my class?
P.S. To call deleteuser method I have to go through userslist method, so @command is certainly not nil.