Ruby on rails #<;ActionController::ParameterMissing:param缺失或值为空:book>;

Ruby on rails #<;ActionController::ParameterMissing:param缺失或值为空:book>;,ruby-on-rails,ruby,actioncontroller,Ruby On Rails,Ruby,Actioncontroller,这是我的控制器 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

这是我的控制器

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
我得到了上面的错误,这里面出了什么问题。有什么想法吗?我正在使用
sqlite3
数据库和
webric
服务器。

检查下面的日志文件

def create
 puts 'params => ' + params
 @book = Book.new(book_params)
“您的rails目录”/logs/development.log

还有一点,您应该像下面那样编写“puts”调试,因为“puts”结果显示在日志文件上方

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

@纳尼,你必须在你的日志中找到类似的东西:

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"=>{....}}

在这里,您需要检查控制器中的参数是否正确。

您确定收到的参数格式正确吗?在异常后在webric日志中检查它们。尝试使用此
params.fetch(:book,{})。permit(:author,:categories,:publisher,:title)
您能解释一下在哪里可以找到webric日志吗??我是新来的@BorisPilgunit保存默认值时,我尝试了@SravanAbout Logs:查看rails项目的日志文件夹。