error_messages_for, can the css be turned off?

I don't think there's an easy answer to turning the CSS off (other
than just not defining that style in your stylesheet) but you can get
the text of the individual error messages with
"error_message_on(object, method)" like:

error_message_on(user, username)
=> already in use

error_message_on(post, title)
=> can not be blank

Hi --

hi andrew, thanks for the answer, i now know how to use error on
message...however, i am still having a problem where when the form is
redisplayed, my fields are shifted due to the addition of divs...

There's a proc that generates that div wrapper, and you can override
it. You can see the original/default one right near the top of
helpers/active_record_helper.rb in the ActionView directory of the
Rails source. You can override it at the bottom of your
config/environment.rb file.

For example, here's a simple replacement proc that will write an error
message in red right next to each offending field:

ActionView::Base.field_error_proc = Proc.new {|html_tag, instance|
  "<p style='color: red'>#{instance.method_name.capitalize}
#{instance.error_message}</p>#{html_tag}"}

A bit too simple for real life, probably, but it shows you the idea.
You can find more info, and some nice pre-written replacement procs,
by googling for field_error_proc.

David

If you just replace that div [block level, and therefore layout up-screwing by default] with a layout-friendly span, it’s pretty much the same as now and can be styled the same but without the layout shifting and breaking unexpectedly.

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
“<span class=“error”>#{html_tag}”
end

Also, because you can change the display of a span [or any element] to “block”, this method is the simplest. Though, now that I think about it… You could just change the display of the div to inline, couldn’t you? Hrm… Seems like there’s a few different ways to get this accomplished.

RSL