Merge pull request #475 from sgmap/474_display_devise_errors_with_flashes
474 display devise errors with flashes
This commit is contained in:
commit
c5300232a5
6 changed files with 29 additions and 10 deletions
|
@ -49,7 +49,7 @@ class Backoffice::AvisController < ApplicationController
|
|||
avis = Avis.find(params[:id])
|
||||
redirect_to url_for(backoffice_dossier_path(avis.dossier_id))
|
||||
else
|
||||
flash[:alert] = gestionnaire.errors.full_messages.join('<br>')
|
||||
flash[:alert] = gestionnaire.errors.full_messages
|
||||
redirect_to url_for(avis_sign_up_path(params[:id], email))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class Backoffice::PrivateFormulairesController < ApplicationController
|
|||
if champs_service_errors.empty?
|
||||
flash[:notice] = "Formulaire enregistré"
|
||||
else
|
||||
flash[:alert] = champs_service_errors.join('<br>').html_safe
|
||||
flash[:alert] = champs_service_errors
|
||||
end
|
||||
end
|
||||
|
||||
|
|
8
app/helpers/application_helper.rb
Normal file
8
app/helpers/application_helper.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
module ApplicationHelper
|
||||
def flash_class(level)
|
||||
case level
|
||||
when "notice" then "alert-success"
|
||||
when "alert" then "alert-danger"
|
||||
end
|
||||
end
|
||||
end
|
8
app/helpers/devise_helper.rb
Normal file
8
app/helpers/devise_helper.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
module DeviseHelper
|
||||
def devise_error_messages!
|
||||
if resource.errors.full_messages.any?
|
||||
flash.now[:alert] = resource.errors.full_messages
|
||||
end
|
||||
''
|
||||
end
|
||||
end
|
|
@ -1,8 +1,11 @@
|
|||
- if flash.notice.present? || flash.alert.present?
|
||||
- if flash.any?
|
||||
#flash_message.center
|
||||
- if flash.notice.present?
|
||||
.alert.alert-success
|
||||
= flash.notice
|
||||
- if flash.alert.present?
|
||||
.alert.alert-danger
|
||||
= flash.alert.html_safe
|
||||
- flash.each do |key, value|
|
||||
- if value.class == Array
|
||||
.alert{ class: flash_class(key) }
|
||||
- value.each do |message|
|
||||
= message
|
||||
%br
|
||||
- else
|
||||
.alert{ class: flash_class(key) }
|
||||
= value
|
||||
|
|
|
@ -178,7 +178,7 @@ describe Backoffice::AvisController, type: :controller do
|
|||
|
||||
it { expect(created_gestionnaire).to be_nil }
|
||||
it { is_expected.to redirect_to avis_sign_up_path(avis_id, invited_email) }
|
||||
it { expect(flash.alert).to eq('Password : Le mot de passe est vide') }
|
||||
it { expect(flash.alert).to eq(['Password : Le mot de passe est vide']) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue