DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Display Rails Validation Error(s) In Non-defaults Places

11.06.2008
| 5190 views |
  • submit to reddit
        Do you want to display rails validation error(s) in non-defaults places? Enjoy! 

App helper:
  def errors_for(object, attribute)
    if errors = object.errors.on(attribute)
    errors = [errors] unless errors.is_a?(Array)
    return "<ul class='blad-form'>" + errors.map {|e| "<li> › " + e + "</li>"}.join + "</ul>"
    end
  end

App view (example)
<%= errors_for @user, :login %>

Code by radarek