【发布时间】:2016-02-12 11:15:20
【问题描述】:
我有自定义 JSON 身份验证 API(没有设计等)。如何将@user.authentication_token 渲染到响应头而不是正文?
在sessions_controller.rb
def create
if @user && @user.authenticate(params[:user][:password])
@user.sign_in_count += 1
@user.save!
render status: 200,
json: { success: true,
info: "Logged in sucessfully.",
data: { auth_token: @user.authentication_token } }
else
render status: :unprocessable_entity,
json: { success: false,
info: "Login failed." }
end
end
【问题讨论】:
标签: ruby-on-rails json authentication