Ruby on Rails - model validation -
i have problem simple model validation. entering materials without sku getting me error message:
nomethoderror in materials#create undefined method `empty?' nil:nilclass
material.rb:
class material < activerecord::base validates :sku, :presence => true end
materials_controler.rb (create part only):
# post /materials # post /materials.json def create @material = material.new(material_params) respond_to |format| if @material.save format.html { redirect_to @material, notice: 'material 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
define @units
in create method