![](/img/trans.png)
[英]ActionController::ParameterMissing (param is missing or the value is empty: bid)
[英]#<ActionController::ParameterMissing: param is missing or the value is empty: book>
這是我的控制器
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
我正在通過這樣的嬰兒車
{ "book":{
"author": "some one",
"categories": "some thing",
"publisher": "some publisher",
"title": "some thing my own"
}
}
我收到上述錯誤,這是什么錯誤。 有任何想法嗎? 我正在使用sqlite3
數據庫和webric
服務器。
檢查以下日志文件。
“您的Rails目錄” /logs/development.log
還有一點,您應該像下面那樣編寫“ puts”調試,因為“ puts”結果顯示在日志文件上方。
def create
puts 'params => ' + params
@book = Book.new(book_params)
@Nani,您必須在日志中找到類似以下內容:
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"=>{....}}
在這里,您需要檢查是否期望控制器中的參數正確。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.