ga-wdi-boston / full-stack-project

Other
8 stars 64 forks source link

ActionController::ParameterMissing (param is missing or the value is empty: movie): #989

Closed 3point14guy closed 7 years ago

3point14guy commented 7 years ago

Trying to do a POST request w this curl:

curl --include --request POST http://localhost:4741/movies \
 --header "Content-Type: application/json" \
 --data '{
   "movies": {
     "movie": "Star Wars",
     "year": "1977",
     "rating": "5"
   }
 }'

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:increate'

Line 18 is:

def create
    @movie = Movie.new(movie_params)
end

and line 49 is:

def movie_params
      params.require(:movie).permit(:movie, :year, :rating)
end

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.

jordanallain commented 7 years ago

"movies": {

looks like you called movies when it should be movie

3point14guy commented 7 years ago

I tried it that way already and I got: 422 Unprocessable Entity

jordanallain commented 7 years ago
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

3point14guy commented 7 years ago

great!

do I have to do drop column and then add column to fix it?

jordanallain commented 7 years ago

you can also rename a column with a migration i believe

jordanallain commented 7 years ago

this looks useful

https://stackoverflow.com/questions/1992019/how-can-i-rename-a-database-column-in-a-ruby-on-rails-migration

3point14guy commented 7 years ago

Thanks. I will fix the column heading and then see if that fixes my error

3point14guy commented 7 years ago

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.

3point14guy commented 7 years ago

I said table name but I meant column name.

jordanallain commented 7 years ago

can you post the schema so we can see what your movies table looks like now?

3point14guy commented 7 years ago
  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
jordanallain commented 7 years ago

can you also post the movie_params from your movies controller?

3point14guy commented 7 years ago
def movie_params
      params.require(:movie).permit(:name, :year, :rating)
    end
jordanallain commented 7 years ago

alright, and what is the new version of your curl script?

3point14guy commented 7 years ago
curl --include --request POST http://localhost:4741/movies \
 --header "Content-Type: application/json" \
 --data '{
   "movies": {
     "name": "Star Wars",
     "year": "1977",
     "rating": "5"
   }
 }'
jordanallain commented 7 years ago

change that movies to movie!!

3point14guy commented 7 years ago

I tried that too and it goes back to 422 Unprocessable Entity

Jcornmanhomonoff commented 7 years ago

Have you tried doing the date as ????-??-??......?

Jcornmanhomonoff commented 7 years ago

Same question with your float...?.?....?

3point14guy commented 7 years ago

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"
   }
 }'
jordanallain commented 7 years ago

do your rails server logs have anything useful?

3point14guy commented 7 years ago

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)

jordanallain commented 7 years ago

can you post the movie serializer?

3point14guy commented 7 years ago

I already made sure to change to the new column name here

class MovieSerializer < ActiveModel::Serializer
  attributes :id, :name, :year, :rating
end
3point14guy commented 7 years ago

Sat down with Jordan and Jess and we determined that I need to be logged in to test my curl requests for my table!