當我嘗試創建它說未定義的方法。Ruby on rails:未定義的方法`[]'爲零:NilClass?
def create
@stock = Stock.find(params[:stock_availabilities][:stock_id])
@stock_availability = StockAvailability.new(stock_availabilities_params)
respond_to do |format|
if @stock_availability.save
format.html { redirect_to stock_path(v_id: @volunteer.id), notice: "stock saved successfully" }
else
@stock_availabilities = StockAvailability.where(stock_id: @stock.id).all
format.html { render 'index' }
end
end
end
凡stock_availabilities
屬於Stock
表。 foreign key
是stock_id
。
在日誌中產生的params爲
Parameters: {
"utf8"=>"✓",
"authenticity_token"=>"ZWxRnGJqwLmhfosIhQ+xdLrG3HJXy1m/dHcizT+Y5+E=",
"stockavailability"=>{
"qty"=>"20",
"price"=>"2000",
"captured_at"=>"26/8/2015"
},
"commit"=>"Save Stockavailability"
}
Completed 404 Not Found in 1ms
更新您的有問題的表格。 –
請發佈錯誤日誌。 – Surya
你通過什麼參數進入這個動作?你的形式和路線是什麼? –