Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated flash errors with correct error messages #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app/controllers/letters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ def create
flash[:notice] = t('flash.saved_letter_successfully')
redirect_to letter_path(@letter)
else
flash[:error] = 'Letter description cannot be empty. Try Again!'
# flash[:error] = 'Letter description cannot be empty. Try Again!'
if @letter.errors.many?
flash[:error] = "There are #{view_context.pluralize(@letter.errors.count,"error")}.
#{@letter.errors.full_messages.join("\n")}"
else
flash[:error] = "There is #{view_context.pluralize(@letter.errors.count,"error")}.
#{@letter.errors.full_messages.join("\n")}"
end
redirect_to root_path
end
end
Expand All @@ -29,7 +36,14 @@ def update
if @letter.update(letter_params)
flash[:notice] = t('flash.updated_letter_successfully')
else
flash[:error] = 'Letter description cannot be empty. Try Again!'
# flash[:error] = 'Letter description cannot be empty. Try Again!'
if @letter.errors.many?
flash[:error] = "There are #{view_context.pluralize(@letter.errors.count,"error")}.
#{@letter.errors.full_messages.join("\n")}"
else
flash[:error] = "There is #{view_context.pluralize(@letter.errors.count,"error")}.
#{@letter.errors.full_messages.join("\n")}"
end
end
redirect_to letter_path(@letter)
end
Expand Down