How to access helpers such as current_user in other models?
How to access current_staff (my Devise model is called 'Staff' instead of User) after logging in -
I am sending request like this - curl -XGET -v -H 'Content-Type: application/json' http://localhost:3000/api/v1/calls/
But getting an error - NameError (uninitialized constant Api::V1::CallsController::AuthorizationException):
app/controllers/api/v1/calls_controller.rb:348:in `authenticate_staff!'
Do we need to send access token in the curl request every time ?
My calls_controller inherits the application controller
class Api::V1::CallsController < Api::V1::ApplicationController
and my application controller -
class Api::V1::ApplicationController < ActionController::API #Note: here is not ::BASE
include DeviseTokenAuth::Concerns::SetUserByToken
The problem is when i run -
curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: tokenpastedhere' http://localhost:3000/api/v1/calls/2.json
I am getting - NameError (uninitialized constant Api::V1::CallsController::AuthorizationException):
which is basically because the current_staff or staff_signed_in helpers are not getting accessible from the calls controller
ruby-on-rails authentication devise devise-token-auth
add a comment |
How to access current_staff (my Devise model is called 'Staff' instead of User) after logging in -
I am sending request like this - curl -XGET -v -H 'Content-Type: application/json' http://localhost:3000/api/v1/calls/
But getting an error - NameError (uninitialized constant Api::V1::CallsController::AuthorizationException):
app/controllers/api/v1/calls_controller.rb:348:in `authenticate_staff!'
Do we need to send access token in the curl request every time ?
My calls_controller inherits the application controller
class Api::V1::CallsController < Api::V1::ApplicationController
and my application controller -
class Api::V1::ApplicationController < ActionController::API #Note: here is not ::BASE
include DeviseTokenAuth::Concerns::SetUserByToken
The problem is when i run -
curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: tokenpastedhere' http://localhost:3000/api/v1/calls/2.json
I am getting - NameError (uninitialized constant Api::V1::CallsController::AuthorizationException):
which is basically because the current_staff or staff_signed_in helpers are not getting accessible from the calls controller
ruby-on-rails authentication devise devise-token-auth
1
Possible duplicate of Devise Authentication using cURL
– MrShemek
Dec 29 '18 at 8:59
when I try curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: RWSL-soU1f_1NWqr44PeNA' -H 'client: 7p9PbNz_AyelGhUEjedXkQ' -H 'uid: user@gmail.com' localhost:3000/api/v1/calls What I get is this SELECT "staffs".* FROM "staffs" WHERE "staffs"."uid" = $1 LIMIT $2 [["uid", "user@gmail.com"], ["LIMIT", 1]] Filter chain halted as :authenticate_staff! rendered or redirected Completed 401 Unauthorized
– Pranav
Dec 29 '18 at 10:03
add a comment |
How to access current_staff (my Devise model is called 'Staff' instead of User) after logging in -
I am sending request like this - curl -XGET -v -H 'Content-Type: application/json' http://localhost:3000/api/v1/calls/
But getting an error - NameError (uninitialized constant Api::V1::CallsController::AuthorizationException):
app/controllers/api/v1/calls_controller.rb:348:in `authenticate_staff!'
Do we need to send access token in the curl request every time ?
My calls_controller inherits the application controller
class Api::V1::CallsController < Api::V1::ApplicationController
and my application controller -
class Api::V1::ApplicationController < ActionController::API #Note: here is not ::BASE
include DeviseTokenAuth::Concerns::SetUserByToken
The problem is when i run -
curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: tokenpastedhere' http://localhost:3000/api/v1/calls/2.json
I am getting - NameError (uninitialized constant Api::V1::CallsController::AuthorizationException):
which is basically because the current_staff or staff_signed_in helpers are not getting accessible from the calls controller
ruby-on-rails authentication devise devise-token-auth
How to access current_staff (my Devise model is called 'Staff' instead of User) after logging in -
I am sending request like this - curl -XGET -v -H 'Content-Type: application/json' http://localhost:3000/api/v1/calls/
But getting an error - NameError (uninitialized constant Api::V1::CallsController::AuthorizationException):
app/controllers/api/v1/calls_controller.rb:348:in `authenticate_staff!'
Do we need to send access token in the curl request every time ?
My calls_controller inherits the application controller
class Api::V1::CallsController < Api::V1::ApplicationController
and my application controller -
class Api::V1::ApplicationController < ActionController::API #Note: here is not ::BASE
include DeviseTokenAuth::Concerns::SetUserByToken
The problem is when i run -
curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: tokenpastedhere' http://localhost:3000/api/v1/calls/2.json
I am getting - NameError (uninitialized constant Api::V1::CallsController::AuthorizationException):
which is basically because the current_staff or staff_signed_in helpers are not getting accessible from the calls controller
ruby-on-rails authentication devise devise-token-auth
ruby-on-rails authentication devise devise-token-auth
edited Dec 29 '18 at 9:32
Pranav
asked Dec 29 '18 at 8:42
PranavPranav
11
11
1
Possible duplicate of Devise Authentication using cURL
– MrShemek
Dec 29 '18 at 8:59
when I try curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: RWSL-soU1f_1NWqr44PeNA' -H 'client: 7p9PbNz_AyelGhUEjedXkQ' -H 'uid: user@gmail.com' localhost:3000/api/v1/calls What I get is this SELECT "staffs".* FROM "staffs" WHERE "staffs"."uid" = $1 LIMIT $2 [["uid", "user@gmail.com"], ["LIMIT", 1]] Filter chain halted as :authenticate_staff! rendered or redirected Completed 401 Unauthorized
– Pranav
Dec 29 '18 at 10:03
add a comment |
1
Possible duplicate of Devise Authentication using cURL
– MrShemek
Dec 29 '18 at 8:59
when I try curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: RWSL-soU1f_1NWqr44PeNA' -H 'client: 7p9PbNz_AyelGhUEjedXkQ' -H 'uid: user@gmail.com' localhost:3000/api/v1/calls What I get is this SELECT "staffs".* FROM "staffs" WHERE "staffs"."uid" = $1 LIMIT $2 [["uid", "user@gmail.com"], ["LIMIT", 1]] Filter chain halted as :authenticate_staff! rendered or redirected Completed 401 Unauthorized
– Pranav
Dec 29 '18 at 10:03
1
1
Possible duplicate of Devise Authentication using cURL
– MrShemek
Dec 29 '18 at 8:59
Possible duplicate of Devise Authentication using cURL
– MrShemek
Dec 29 '18 at 8:59
when I try curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: RWSL-soU1f_1NWqr44PeNA' -H 'client: 7p9PbNz_AyelGhUEjedXkQ' -H 'uid: user@gmail.com' localhost:3000/api/v1/calls What I get is this SELECT "staffs".* FROM "staffs" WHERE "staffs"."uid" = $1 LIMIT $2 [["uid", "user@gmail.com"], ["LIMIT", 1]] Filter chain halted as :authenticate_staff! rendered or redirected Completed 401 Unauthorized
– Pranav
Dec 29 '18 at 10:03
when I try curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: RWSL-soU1f_1NWqr44PeNA' -H 'client: 7p9PbNz_AyelGhUEjedXkQ' -H 'uid: user@gmail.com' localhost:3000/api/v1/calls What I get is this SELECT "staffs".* FROM "staffs" WHERE "staffs"."uid" = $1 LIMIT $2 [["uid", "user@gmail.com"], ["LIMIT", 1]] Filter chain halted as :authenticate_staff! rendered or redirected Completed 401 Unauthorized
– Pranav
Dec 29 '18 at 10:03
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968040%2fhow-to-access-helpers-such-as-current-user-in-other-models%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53968040%2fhow-to-access-helpers-such-as-current-user-in-other-models%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Possible duplicate of Devise Authentication using cURL
– MrShemek
Dec 29 '18 at 8:59
when I try curl -XGET -v -H 'Content-Type: application/json' -H 'access-token: RWSL-soU1f_1NWqr44PeNA' -H 'client: 7p9PbNz_AyelGhUEjedXkQ' -H 'uid: user@gmail.com' localhost:3000/api/v1/calls What I get is this SELECT "staffs".* FROM "staffs" WHERE "staffs"."uid" = $1 LIMIT $2 [["uid", "user@gmail.com"], ["LIMIT", 1]] Filter chain halted as :authenticate_staff! rendered or redirected Completed 401 Unauthorized
– Pranav
Dec 29 '18 at 10:03