foodsoft/app/controllers/stockit_controller.rb
2013-01-28 20:46:35 +01:00

57 lines
1.5 KiB
Ruby

class StockitController < ApplicationController
def index
@stock_articles = StockArticle.elements_for_index
@stock_article_selection = StockArticleSelection.new
end
def new
@stock_article = StockArticle.new
end
def create
@stock_article = StockArticle.new(params[:stock_article])
if @stock_article.save
redirect_to stock_articles_path, :notice => "Lagerartikel wurde gespeichert."
else
render :action => 'new'
end
end
def edit
@stock_article = StockArticle.find(params[:id])
end
def update
@stock_article = StockArticle.find(params[:id])
if @stock_article.update_attributes(params[:stock_article])
redirect_to stock_articles_path, :notice => "Lagerartikel wurde gespeichert."
else
render :action => 'edit'
end
end
def destroy
StockArticle.find(params[:id]).destroy
redirect_to stock_articles_path
rescue => error
flash[:error] = "Ein Fehler ist aufgetreten: " + error.message
redirect_to stock_articles_path
end
#TODO: Fix this!!
def articles_search
@articles = Article.not_in_stock.limit(8).where('name LIKE ?', "%#{params[:term]}%")
render :json => @articles.map(&:name)
end
def fill_new_stock_article_form
article = Article.find(params[:article_id])
@supplier = article.supplier
stock_article = @supplier.stock_articles.build(
article.attributes.reject { |attr| attr == ('id' || 'type')}
)
render :partial => 'form', :locals => {:stock_article => stock_article}
end
end