Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8312883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:18:30+00:00 2026-06-08T20:18:30+00:00

I have an app that uses devise for login. I have a login form

  • 0

I have an app that uses devise for login. I have a login form in a web app that authenticates a user to the database and simply returns the @user hash as a json string.

The goal is to get the users authenticate the user and retrieve their authentication_token for future use in the app to prevent the user from having to continually log in.

The problem is that I can’t get authentication_token to be included in the returned json.

My user.rb Model

attr_accessible :authentication_token, :email, :password, :password_confirmation, :remember_me,  :bio, :confirmed, :deposit, :email, :fri25, :mon21, :name, :paid, :picture, :sat26, :sun20, :sun27, :thur24, :tue22, :wed23

clearly includes the authentication_token symbol.

Then in the session controller I have a custom action called newApi which runs a simple authentication method and responds with the @user hash as json.

def newapi
 @user = User.authenticate(params[:email],params[:password])
 respond_to do |format|
   format.json { render json: @user }
 end

eend

Yet no matter what I do the authentication token is not included with the json response. Am I missing something obvious? Why is it not included?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:18:32+00:00Added an answer on June 8, 2026 at 8:18 pm

    I ended up solving the problem myself by using jbuilder.

    Essentially you just remove the render json: @user call and use a jbuilder template.

    in newapi.json.jbuilder

    json.(
      @user, 
      :authentication_token, 
      :email, 
      :password, 
      :password_confirmation, 
      :remember_me,
      :bio, 
      :confirmed, 
      :deposit, 
      :email, 
      :fri25, 
      :mon21, 
      :name, 
      :paid, 
      :picture, 
      :sat26, 
      :sun20, 
      :sun27, 
      :thur24, 
      :tue22, 
      :wed23
    )
    

    Review their docs if you got this route as there are plenty of It does everything I needed and more and is the only way we do api returns now. If you’ve not used it before go check it out! it make API endpoints amazingly simple.

    Nick Knudson’s answer is also valid if you want to roll your own setup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails app that uses Devise for user auth. In localhost:3000 my
I have a rails app that is using Devise, with a User model, no
I have a web app which uses Devise for authentication. It is a site
I have a web app which uses Devise for authentication. It is a site
I currently have an app that uses regular Devise authentication for logging in and
I have an app that uses Devise to do account creation, etc. But I
I currently have a simple app that includes user authentication through devise and a
I have an app that uses an SQLite database. With the advent of iCloud
I have an app that uses Devise and CanCan. in the config>initializers>Abiliity.rb class Ability
I have a Rails app that was already setup to use devise with User

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.