Knock: Knock wont work with namespaced routes

Created on 22 Nov 2016  路  3Comments  路  Source: nsarno/knock

I have the following route 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 that, I expect to be able to make a POST request like:

POST http://api.domain.com/v1/user_token

But this request gives me the following error:

NameError: uninitialized constant API::V1::User

It seems like, knock are trying to access my model User from the same namespace where the controller UserTokenController is. But my model User is 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

Ruby Version: 2.3.2
Rails Version: 5.0.0.1

What I am missing?

Most helpful comment

@nsarno I am using master branch now. And its working.

All 3 comments

Today I noticed that using a latest published version (2.0) gives me the error.

gem 'knock', '~> 2.0' # wont work

But if I setup to get the gem from github, like:

gem 'knock', github: 'psantos10/knock', branch: 'master'

Its works!

@psantos10 this has been fixed in #95 thanks to @albertobajo. I'll release a new version soon. In the meantime, using master works.

@nsarno I am using master branch now. And its working.

Was this page helpful?
0 / 5 - 0 ratings