Hidden gem – error_message_on
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:

8 comments.
Leave a Reply