Skip to content

NoMethodError when current_user is called #947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jraczak opened this issue Aug 29, 2017 · 2 comments
Closed

NoMethodError when current_user is called #947

jraczak opened this issue Aug 29, 2017 · 2 comments

Comments

@jraczak
Copy link

jraczak commented Aug 29, 2017

I'm testing an API using devise_token_auth using Postman. Sign in works with no problem and returns the expected body and headers. I store the headers (I've manually verified that the correct header values are stored) and provide them in a subsequent call to create an object. In this case, it's a task. My controller builds on the current_user which should be available via devise_token_auth as I've provided the headers with the call. However, I get this error

NoMethodError (undefined method tasks' for nil:NilClass)`

which is triggered on this line

@task = current_user.tasks.create!(task_params)

What am I doing wrong? Or is this a bug?

@rmcsharry
Copy link

@jraczak If you mounted the gem at 'api' or even 'api/v1' namespace then the methods change:
current_user becomes current_api_user or even current_api_v1_user

@zachfeldman
Copy link
Contributor

Potential solution posted. @jraczak feel free to reopen if it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants