Closed nriser closed 7 years ago
{"user":["must exist"]}
message makes me the the database (schema) has a rule that a user_id
must be present to create a new Flashcard. Are you passing a user_id
when you create it? Add a binding.pry
and test out the params
to find out.
def create
binding.pry # what is params? what is flashcard_params?
@flashcard = Flashcard.new(flashcard_params)
if @flashcard.save
render json: @flashcard, status: :created, location: @flashcard
else
render json: @flashcard.errors, status: :unprocessable_entity
end
end
Also, the next issue you are going to have is related to this https://github.com/ga-wdi-boston/full-stack-project/issues/814. Read that issue. You will want to consider changing your Controller to inherit from OpenReadController
or ProtectedController
not ApplicationController
so you can access current_user
.
@MicFin Thank you for your reply. binding.pry was useful. I followed the example in https://github.com/ga-wdi-boston/full-stack-project/issues/814 and now the curl script for create works.
When I run the curl script for creating a new flashcard, I get a '422 Unprocessable Entity' error in rails server. I signed up and signed in with curl and passed in the token into my curl command for create, but it tells me the error, '{"user":["must exist"]}'.
curl script
flashcard controller snippet:
flashcard model