SameShirtEveryDay.com

Personal blog of the one called Alex Gorbatchev, from Toronto, Canada.

Hidden gem – error_message_on

Posted on June 3rd, 2007 by Alex Gorbatchev. In Rails. 8 comments!

Story goes like this: I was trying to find a way to display form error messages in a pretty tight place. Using your regular error_messages_for creates a pretty long list and makes my page scroll.

Turns out, ActiveRecordHelper has another far much less known method called error_message_on. I thought it was just me at first, but a quick look on Google revealed that error_message_on returns only 3,240 hits where as error_messages_for comes in at 16,200 hits.

Here’s how this looks like in code:

<label for="email">Email <%= error_message_on :user, :email %></label>
<%= f.text_field(:email) %>

And with a little bit of CSS magic this is what the form looks like:

You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

8 comments.

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> , rel="nofollow" in use - no link dropping, no keywords or domains as names; do not spam, and do not advertise!

home
Subscribe to this blog Follow me on Twitter My bookmarks on Delicious My photography on Flickr