Reputation: 2032
I have seen this error in many threads, and none of the solutions - which is basically one and it didn't work for me. so perhaps I did something else wrong.
This is my controller: *copied from api on rails tutorial - it worked for the guy..
class Api::V1::SessionsController < ApplicationController
respond_to :json
def create
user_password = params[:session][:password]
user_name = params[:session][:user_name]
user = user_name.present? && User.find_by(user_name: user_name)
if user.valid_password? user_password
sign_in user, store: false
user.generate_authentication_token!
user.save
render json: user, status: 200, location: [:api, user]
else
render json: { errors: "Invalid email or password" }, status: 422
end
end
end
I tried using location: [:api, :v1, user]
and it still didn't work
I have no idea what I did wrong, and have no idea on where to look for errors. The only difference between me and the tutorial is that I am using Rails 4.2.0.
Upvotes: 0
Views: 49
Reputation: 2837
Try this:
render json: user, status: 201, location: api_v1_user_path
Upvotes: 1