I use Devise and Basic HTTP Authentication to access user areas from a mobile app. When the user enters its details in the app and it tries to “login” (you don’t actually login with basic auth as you send the credentials with each request) I want to get a response back with the user info, like user ID and email.
When I try to get a resource I get a response like this:
[
-
{
email: "em...@example.com"
username: "Example"
}
-
[
-
{
created_at: "2011-07-26T11:30:55Z"
id: 1
title: "Test"
updated_at: "2011-07-26T11:30:55Z"
user_id: 1
}
-
{
created_at: "2011-07-26T16:53:26Z"
id: 2
title: "Test2"
updated_at: "2011-07-26T16:53:26Z"
user_id: 1
}
]
]
So I get the user object at the beginning. However, I need to add the user ID as well. I can’t use the user_id in the items because that won’t be rendered if the user has no items.
Any tips?
You probably need to extend
Devise::SessionsConroller. In your controllers folder, add a users folder and then add a file calledsessions_controller.rbthat contains this:In
your routes.rb:EDIT
Try this. Take that line out of your
routes.rb. Inapplication_controller.rbadd this: