I am using Knock for JWT authentication for Rails 5 API.
I have this Routes file:
Rails.application.routes.draw do
namespace :api, constraints: { subdomain: 'api' }, path: '/' do
namespace :v1 do
post 'user_token' => 'user_token#create'
end
end
end
With this, I expect to be able to make a POST request to create new token like this:
but this request gives me the following error:
NameError: uninitialized constant API::V1::User
What I can understand is that Knock is trying to access the model User
on the same namespace where the controller ( user_token_controller
) is. But my model are not namespaced:
class User < ApplicationRecord
has_secure_password
#...
end
My user_token_controller.rb
module API
module V1
class UserTokenController < Knock::AuthTokenController
end
end
end
What I dong wrong?
It's a bug already fixed but not yet published.
The temporary solution was using the gem from github code like:
gem 'knock', github: 'psantos10/knock', branch: 'master'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.