简体   繁体   中英

#<ActionController::ParameterMissing: param is missing or the value is empty: book>

this is my controller

class BooksController < ApplicationController 
 def create
   @book = Book.new(book_params)
   if @book.save
     render json: @book, status: 201
   else
    render json: { error: "check attributes again", status: 400 }, status: 400
   end
  end
 private

 def book_params
  params.require(:book).permit(:author, :categories, :publisher, :title)
 end
end

i am passing prams like this

{  "book":{
      "author": "some one",
      "categories": "some thing",
      "publisher": "some publisher",
      "title": "some thing my own"
      }
}

I am getting the above error what is the wrong in it. Any ideas? I am using sqlite3 data base and webric server.

Check below log file.

"your rails directory"/logs/development.log

And one more point, you should write 'puts' debug like below, because 'puts' results display above log file.

def create
 puts 'params => ' + params
 @book = Book.new(book_params)

@Nani, you have to find in your logs something similar to this:

Started POST "/books" for 127.0.0.1 at 2016-02-18 18:58:17 +0200
Processing by BooksController#create as JS
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"....", "book"=>{....}}

And here you need to check if you expecting correct parameters in your controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM