I have the following methods for Create and Update in my Controller:
def new
if request.post?
@article = Article.new(article_params)
@article.user = @user
if @article.save
redirect_to :admin_articles, :flash => { success: t(:article_created) }
end
else
@article = Article.new
end
end
def edit
if request.patch?
if @article.update(article_params)
redirect_to :admin_articles, :flash => { success: t(:article_updated) }
end
end
end
And I have the following for the article_params:
def article_params
article_params = params[:article].permit(:category_id, :title, :slug, :article_type, :content, :link, :summary)
if params[:tags].present?
tags = params[:tags].split ','
tags_array = Array.new
tags.each do |t|
tags_array.append Tag.find_or_create_by slug: t
end
article_params[:tags] = tags_array
end
article_params
end
When I do the Update it saves properly, but when I try to do the Create it says Article Tags is invalid. Does anyone know what I am doing wrong?