Hi! 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, email (not password) etc. - So, is there a way to do this out of the box with Devise? If not I guess I could just create a "login" controller with an "index"-action that just has: before_filter :authenticate_user! respond_to :json ... respond_with current_user ... So when I do a request from my app to http://example.com/login/ Devise will return an error by default if the username and password are incorrect, and if the credentials are correct it outputs the user object as JSON. Are there any issues with the approach above? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/DZTrqDb7TsUJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Actually, the user is outputted when accessing other resources, I can work with that :) One issue, I want the user object to also show the user ID. Now it only shows the email and username. It renders the json like this: [ - - { - email: "email-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org" - 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 } ] ] I can''t use the user_id in the items because if the user don''t have any items it would not be displayed. Any tips? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/_P5-EDkGjj8J. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ok. Adding attr_accessible :id to my model works. But is it safe to do it like this? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/uff6lPVoj-oJ. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Seemingly Similar Threads
- getting devise to return json data when signing out
- create object after before_filter :authenticate_user!
- creating an account with a username in devise
- Devise is causing the [The change you wanted was rejected.] Error...
- Controller Testing + Devise = boom (undefined @controller, request)