summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/helpers/application_helper.rb14
-rw-r--r--app/views/boards/_form.html.erb2
-rw-r--r--app/views/documents/_form.html.erb2
-rw-r--r--app/views/groups/_form.html.erb2
-rw-r--r--app/views/news/_form.html.erb3
-rw-r--r--test/functional/my_controller_test.rb2
6 files changed, 20 insertions, 5 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 175fb5109..313b0f933 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -945,6 +945,20 @@ module ApplicationHelper
remote_form_for(*args, &proc)
end
+ def error_messages_for(*objects)
+ html = ""
+ objects = objects.map {|o| o.is_a?(String) ? instance_variable_get("@#{o}") : o}.compact
+ errors = objects.map {|o| o.errors.full_messages}.flatten
+ if errors.any?
+ html << "<div id='errorExplanation'><ul>\n"
+ errors.each do |error|
+ html << "<li>#{h error}</li>\n"
+ end
+ html << "</ul></div>\n"
+ end
+ html.html_safe
+ end
+
def back_url_hidden_field_tag
back_url = params[:back_url] || request.env['HTTP_REFERER']
back_url = CGI.unescape(back_url.to_s)
diff --git a/app/views/boards/_form.html.erb b/app/views/boards/_form.html.erb
index d80c84717..736028bb1 100644
--- a/app/views/boards/_form.html.erb
+++ b/app/views/boards/_form.html.erb
@@ -1,4 +1,4 @@
-<%= f.error_messages %>
+<%= error_messages_for @board %>
<div class="box tabular">
<p><%= f.text_field :name, :required => true %></p>
diff --git a/app/views/documents/_form.html.erb b/app/views/documents/_form.html.erb
index b5b5fa410..53d8fc3bb 100644
--- a/app/views/documents/_form.html.erb
+++ b/app/views/documents/_form.html.erb
@@ -1,4 +1,4 @@
-<%= f.error_messages %>
+<%= error_messages_for @document %>
<div class="box tabular">
<p><%= f.select :category_id, DocumentCategory.active.collect {|c| [c.name, c.id]} %></p>
diff --git a/app/views/groups/_form.html.erb b/app/views/groups/_form.html.erb
index aab2a073e..bca919b39 100644
--- a/app/views/groups/_form.html.erb
+++ b/app/views/groups/_form.html.erb
@@ -1,4 +1,4 @@
-<%= f.error_messages %>
+<%= error_messages_for @group %>
<div class="box tabular">
<p><%= f.text_field :lastname, :label => :field_name %></p>
diff --git a/app/views/news/_form.html.erb b/app/views/news/_form.html.erb
index a0d2167a9..ad28e12b2 100644
--- a/app/views/news/_form.html.erb
+++ b/app/views/news/_form.html.erb
@@ -1,4 +1,5 @@
-<%= f.error_messages %>
+<%= error_messages_for @news %>
+
<div class="box tabular">
<p><%= f.text_field :title, :required => true, :size => 60 %></p>
<p><%= f.text_area :summary, :cols => 60, :rows => 2 %></p>
diff --git a/test/functional/my_controller_test.rb b/test/functional/my_controller_test.rb
index cac6a14ad..a89af91a2 100644
--- a/test/functional/my_controller_test.rb
+++ b/test/functional/my_controller_test.rb
@@ -95,7 +95,7 @@ class MyControllerTest < ActionController::TestCase
:new_password_confirmation => 'hello2'
assert_response :success
assert_template 'password'
- assert_tag :tag => "div", :attributes => { :class => "errorExplanation" }
+ assert_error_tag :content => /Password doesn't match confirmation/
# wrong password
post :password, :password => 'wrongpassword',