Override flash message - help

How can I modify the flash message that is displayed on a validates_*
check? I used the :message => “” parameter, but it still gives me an
annoying “Test : Please ensure you have entered the test message”. I
wanted to get rid of the "Test: " and the above “6 errors prohibited
this table from being saved” I looked at the source of
validates_presence_of and I only found the :message, nothing else to
help me validate. Can someone help me?

Try overriding error_messages_for(). Here is an example that may work
for you.

  def error_messages_for(object_name)
    if object_name == :page && !flash[:error].nil?
      return content_tag(:div, content_tag(:ul, content_tag(:li,

flash[:error])), :class => “flash error”)
object = assigns["#{object_name.to_s}"]
if object && !object.errors.empty?
content_tag(:ul, object.errors.collect {
|attribute, msg| content_tag(:li, msg) }),
:class => “flash error”)

Hope this helps,

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs