Skip to content
Extraits de code Groupes Projets
Valider 512d96bd rédigé par Lukas Matt's avatar Lukas Matt
Parcourir les fichiers

Display validation errors to user

parent 6309e1a4
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -27,7 +27,8 @@ class ReportController < ApplicationController
end
def create
if current_user.reports.create! report_params
report = current_user.reports.new(report_params)
if report.save
flash.now[:notice] = I18n.t 'report.status.created'
render :nothing => true, :status => 200
else
......
......@@ -4,7 +4,7 @@ class Report < ActiveRecord::Base
validates :post_type, presence: true
validates :text, presence: true
validate :entry_exists, :on => :create
validate :entry_does_not_exist, :on => :create
belongs_to :user
belongs_to :post
......@@ -12,7 +12,7 @@ class Report < ActiveRecord::Base
after_commit :send_report_notification, :on => :create
def entry_exists
def entry_does_not_exist
if Report.where(post_id: post_id, post_type: post_type).exists?(user_id: user_id)
errors[:base] << 'You cannot report the same post twice.'
end
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter