Skip to content

Commit

Permalink
Try to fix @model missing warning in article form
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Jan 4, 2025
1 parent 4e8c18e commit 8440b7e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ def edit
# ---------- Actions to Modify data: (create, update, destroy, etc.) ---------

def create
return render(:new) if flash_missing_title?

@article = Article.new(
title: params[:article][:title],
body: params[:article][:body],
title: params.dig(:article, :title),
body: params.dig(:article, :body),
user_id: @user.id
)
return render(:new) if flash_missing_title?

@article.save
redirect_to(article_path(@article.id))
end
Expand All @@ -79,8 +79,8 @@ def update
@article = Article.find(params[:id])
return render(:edit) if flash_missing_title?

@article.title = params[:article][:title]
@article.body = params[:article][:body]
@article.title = params.dig(:article, :title)
@article.body = params.dig(:article, :body)

save_any_changes
redirect_to(article_path(@article.id))
Expand All @@ -105,7 +105,7 @@ def ignore_request_unless_permitted

# add flash message if title missing
def flash_missing_title?
return false if params[:article][:title].present?
return false if params.dig(:article, :title).present?

flash_error(:article_title_required.t)
true
Expand Down

0 comments on commit 8440b7e

Please sign in to comment.