У меня есть этот код в моем ApplicationController
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def authenticate!
# unless current_user
if current_user
current_user
else
render json: { 'error' => {'message' => 'Invalid access token', 'code' => 301 } }
return
end
end
def current_user
return @current_user if @current_user.present?
user = User.find_by(access_token: params.delete(:token))
if user.present?
@current_user = user
else
false
end
end
end
, и я аутентифицирую пользователя с
class Api::V1::RegisterController < ApplicationController
layout nil
skip_before_action :verify_authenticity_token
def get_user
authenticate!
render json: {'hello' => 'hi'}
end
end
, он выдает мне ошибку Double Render
.Как я могу отобразить сообщение о недействительном токене доступа, если токен доступа пользователя отсутствует в моей базе данных, и вернуть данные пользователя, если они есть?* но я получаю ошибку.
undefined local variable or method `render_invalid_access' for ApplicationController:Class