2
我有一個簡單的模型驗證問題。 輸入材料沒有SKU讓我錯誤信息:Ruby on Rails - 模型驗證
材料NoMethodError#創建未定義的方法`空?'對於 零:NilClass
material.rb:
class Material < ActiveRecord::Base
validates :sku, :presence => true
end
materials_controler.rb(僅創建部分):
# POST /materials
# POST /materials.json
def create
@material = Material.new(material_params)
respond_to do |format|
if @material.save
format.html { redirect_to @material, notice: 'Material was successfully created.' }
format.json { render :show, status: :created, location: @material }
else
format.html { render :new }
format.json { render json: @material.errors, status: :unprocessable_entity }
end
end
end
我缺少'@ categories'和'@ units'。謝謝。 – Robert