knock icon indicating copy to clipboard operation
knock copied to clipboard

Entity Name returning module::module::model

Open danwetherald opened this issue 9 years ago • 2 comments

This method is not being called properly when in sub modules.

def entity_name self.class.name.scan(/\w+/).last.split('TokenController').first end

For instance I was getting back Api::V1::User rather than User.

PS: Once I went back to 1.4 - everything is good.

Thanks,

Dan

danwetherald avatar Dec 02 '16 10:12 danwetherald

I also had the same behaviour, wasn't sure whether it was by design or not so had to override entity_name to return a non module'd name

    def entity_name
      'Subscriber'
    end

Perhaps this should be part of the supported API for customisations?

crafterm avatar Dec 07 '16 04:12 crafterm

I also have problem with how Knock handles namespaces (I use namespace V1 for both my models and my controllers). I found two similar issues on the matter in this repository: #120 "Knock wont work with namespaced routes" and #79 "Namespacing models".

How does the current implementation work? Are there some cases that are not yet supported? Maybe it's time to add a section about namespaces on the readme?

Update

My bad. There are actually already a section in the readme about namespaces:

If you're using a namespaced model, Knock won't be able to infer it automatically from the method name. Instead you can use authenticate_for directly like this:

But I did not get this to work without overriding entity_name as @crafterm suggested above.

ehannes avatar Feb 06 '17 09:02 ehannes