I am making an ember and rails app.
I am trying to do a post request to http://localhost:3000/candidates
My request is getting a 200 and is creating a record but everything is nil: Why is this?
#<Candidate id: 15, name: nil, email: nil, created_at: "2018-08-23 22:28:07", updated_at: "2018-08-23 22:28:07">
here is my controller code:
class CandidatesController < ApplicationController
# POST /candidates
# def create
# @candidate = Candidate.create!(candidate_params)
# json_response(@candidate, :created)
# end
def create
puts "create"
puts params
puts candidate_params
candidate = Candidate.create!(candidate_params)
if candidate.save
render jsonapi: candidate
else
render jsonapi_errors: candidate.errors
end
end
private
def candidate_params
# whitelist params
params.permit(:name, :email)
end
end
and here is my ember code:
import Ember from "ember";
export default Ember.Route.extend({
model() {
// return this.get("store").findAll("candidate");
},
actions: {
createCandidate() {
console.log("create candidate");
let candidate = this.get("store").createRecord("candidate", {
id: 1,
name: "Katie",
email: "katie@gmail.com"
});
candidate.save();
}
}
});
I am also getting this error in my js console: SyntaxError: Unexpected end of JSON input
I am using the 'jsonapi-rails' gem
Thanks, Kato
Aucun commentaire:
Enregistrer un commentaire