Fix new stock article failing
This commit is contained in:
parent
f9ffa0caff
commit
be287cf67e
2 changed files with 20 additions and 21 deletions
|
@ -40,12 +40,11 @@ class StockitController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@stock_article = StockArticle.new(params[:stock_article])
|
@stock_article = StockArticle.new({quantity: 0}.merge(params[:stock_article]))
|
||||||
if @stock_article.valid? && @stock_article.save
|
@stock_article.save!
|
||||||
render :layout => false
|
render :layout => false
|
||||||
else
|
rescue ActiveRecord::RecordInvalid
|
||||||
render :action => 'new', :layout => false
|
render :action => 'new', :layout => false
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@ -56,11 +55,10 @@ class StockitController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@stock_article = StockArticle.find(params[:id])
|
@stock_article = StockArticle.find(params[:id])
|
||||||
if @stock_article.update_attributes(params[:stock_article])
|
@stock_article.update_attributes!(params[:stock_article])
|
||||||
render :layout => false
|
render :layout => false
|
||||||
else
|
rescue ActiveRecord::RecordInvalid
|
||||||
render :action => 'edit', :layout => false
|
render :action => 'edit', :layout => false
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|
|
@ -5,6 +5,8 @@ class StockArticle < Article
|
||||||
|
|
||||||
scope :available, -> { undeleted.where('quantity > 0') }
|
scope :available, -> { undeleted.where('quantity > 0') }
|
||||||
|
|
||||||
|
validates :quantity, presence: true, numericality: {greater_than_or_equal_to: 0}
|
||||||
|
|
||||||
before_destroy :check_quantity
|
before_destroy :check_quantity
|
||||||
|
|
||||||
# Update the quantity of items in stock
|
# Update the quantity of items in stock
|
||||||
|
@ -46,4 +48,3 @@ class StockArticle < Article
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue