我有一個使用devise進行登錄的應用程序。我在Web應用程序中有一個登錄表單,用於向數據庫驗證用戶身份,並簡單地將@user散列作爲json字符串返回。使用{render json時出現缺失屬性:}
的目標是讓用戶認證用戶並檢索其authentication_token在App將來使用,以防止用戶不必不斷登錄。
的問題是,我不能讓authentication_token到被包含在返回的json中。
我user.rb型號
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
明確包括authentication_token符號。
然後在會話控制器中,我有一個名爲newApi的自定義操作,它運行一個簡單的身份驗證方法並以@son散列作爲json作出響應。
def newapi
@user = User.authenticate(params[:email],params[:password])
respond_to do |format|
format.json { render json: @user }
end
eend
然而不管我做什麼,認證令牌不包含在JSON響應。我錯過了明顯的東西嗎?爲什麼不包括在內?
解決方案在哪裏? You'e「回答」您自己的問題(未提供解決方案)標記爲正確的問題,甚至沒有投票答案,導致您的解決方案。這真的不是使用Stackoverflow的方式。 – lcguida 2014-09-18 14:24:42
更新的答案提供了一個示例。 – JonathanSimmons 2016-02-01 15:50:00