Reputation: 4865
I am new to rails. I want to know the best way to handle inputs errors in rails. Using :message
in validates_format_of method
then checking in the views the value of the hash or initializing the model with a ActiveModel::Errors.new
, and then using it in the views (passing in the model attr_reader :errors
), or other any way ?
Upvotes: 0
Views: 148
Reputation: 6485
A good way to validate input errors is to have both client-side and server-side validations. You can rely on Rails validators on your models, and on the front end you can either use the newer HTML elements, javascript, or a combination of both.
With regards to Rails validations specifically, I don't think you need to stray too far from the conventions. Obviously if you need a different strategy you can definitely incorporate it, but at that point I would definitely suggest adding tests (which is not something I typically do for Rails validations).
Upvotes: 0
Reputation: 2003
I use :message
invalidates_format_of method
then checking in the views, This is a universal practice
The guide http://guides.rubyonrails.org/active_record_validations_callbacks.html#error_messages-and-error_messages_for
Upvotes: 2