In my code I write my registration code and after it i call sign_in method to return user with client , uid and access-token included in the header but when calling the sign_in , it returns the user object only and the header not included(uid,access-token,client)
promoter = User.find_by_email(params[:email])
if(promoter)
render json: {message:"this email is already exist"} , status: 422
else
@promoter = Promoter.new(promoter_params)
user = User.create(:email => params[:email],:password => params[:password],:user_role_id => 4)
@promoter.user_id = user.id
if @promoter.save
resource = User.find_by_email(params[:email])
puts(resource)
if resource.valid_password?(params[:password])
puts("user ok ")
r = sign_in :user, resource
render json: r,:methods => [:uid,:client] , status: 200
end
else
render json: @promoter.errors , status: 422
end
end
the result is
"exception": "#<NoMethodError: undefined method `client' for #<User:0x00007f67d46df018>>",
I use this to call api
puts "#{request.protocol}#{request.host_with_port}"
params = {"email" => "test8@gmail.com", "password" => "12121212"}
x = Net::HTTP.post_form(URI.parse("#{request.protocol}#{request.host_with_port}/auth/sign_in"), params)
render json: x.body
but it also cannot render the header
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.