Closed 3point14guy closed 7 years ago
"movies": {
looks like you called movies when it should be movie
I tried it that way already and I got: 422 Unprocessable Entity
def movie_params
params.require(:movie).permit(:movie, :year, :rating)
end
you shouldn't have a column that is named the same as the table
great!
do I have to do drop column and then add column to fix it?
you can also rename a column with a migration i believe
Thanks. I will fix the column heading and then see if that fixes my error
Ok. I changed the table name and updated my controller file to reflect the new column name on line 49.
I still get the same error.
I said table name but I meant column name.
can you post the schema so we can see what your movies table looks like now?
create_table "movies", force: :cascade do |t|
t.string "name"
t.date "year"
t.float "rating"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
can you also post the movie_params from your movies controller?
def movie_params
params.require(:movie).permit(:name, :year, :rating)
end
alright, and what is the new version of your curl script?
curl --include --request POST http://localhost:4741/movies \
--header "Content-Type: application/json" \
--data '{
"movies": {
"name": "Star Wars",
"year": "1977",
"rating": "5"
}
}'
change that movies to movie!!
I tried that too and it goes back to 422 Unprocessable Entity
Have you tried doing the date as ????-??-??
......?
Same question with your float...?.?
....?
I had thought about that on the date at one point, but saw something shiny and didn't think about it again. Changing the input on both those parameters did not affect the outcome:
422 Unprocessable Entity
curl --include --request POST http://localhost:4741/movies \
--header "Content-Type: application/json" \
--data '{
"movie": {
"name": "Star Wars",
"year": "1977-01-10",
"rating": "5.0"
}
}'
do your rails server logs have anything useful?
not to me, but that's not saying much.
Started POST "/movies" for 127.0.0.1 at 2017-07-21 15:54:44 -0400 Processing by MoviesController#create as / Parameters: {"movie"=>{"name"=>"Star Wars", "year"=>"1977-01-10", "rating"=>"5.0"}} (0.3ms) BEGIN (0.2ms) ROLLBACK [active_model_serializers] Rendered ActiveModel::Serializer::Null with ActiveModel::Errors (0.16ms) Completed 422 Unprocessable Entity in 6ms (Views: 1.0ms | ActiveRecord: 0.5ms)
can you post the movie serializer?
I already made sure to change to the new column name here
class MovieSerializer < ActiveModel::Serializer
attributes :id, :name, :year, :rating
end
Sat down with Jordan and Jess and we determined that I need to be logged in to test my curl requests for my table!
Trying to do a POST request w this curl:
I get this error: ActionController::ParameterMissing (param is missing or the value is empty: movie): which point to these two lines of code: app/controllers/movies_controller.rb:49:in
movie_params' app/controllers/movies_controller.rb:18:in
create'Line 18 is:
and line 49 is:
The 'movie' the error is referring to is there. I am not sure what more this error is telling me to look at or do.