use Strong Parameters for Article

This commit is contained in:
JuliusR 2021-12-18 15:48:51 +01:00
parent 81ba5ab20e
commit 894c54421b

View file

@ -52,7 +52,7 @@ class ArticlesController < ApplicationController
# POST /supplier/1/articles # POST /supplier/1/articles
# POST /supplier/1/articles.xml # POST /supplier/1/articles.xml
def create def create
@article = Article.new(params[:article]) @article = Article.new(article_params)
respond_to do |format| respond_to do |format|
if @article.save if @article.save
flash[:notice] = 'Article was successfully created.' flash[:notice] = 'Article was successfully created.'
@ -70,7 +70,7 @@ class ArticlesController < ApplicationController
def update def update
@article = @supplier.articles.find(params[:id]) @article = @supplier.articles.find(params[:id])
respond_to do |format| respond_to do |format|
if @article.update(params[:article]) if @article.update(article_params)
flash[:notice] = 'Article was successfully updated.' flash[:notice] = 'Article was successfully updated.'
format.html { redirect_to supplier_article_url(@article.supplier, @article) } format.html { redirect_to supplier_article_url(@article.supplier, @article) }
format.xml { head :ok } format.xml { head :ok }
@ -144,4 +144,26 @@ class ArticlesController < ApplicationController
redirect_to supplier_articles_url(@supplier) redirect_to supplier_articles_url(@supplier)
end end
private
def article_params
params
.require(:article)
.permit(
:name,
:number,
:note,
:manufacturer,
:origin,
:unit,
:price,
:tax,
:deposit,
:unit_quantity,
:category,
:scale_quantity,
:scale_price,
:supplier_id
)
end
end end