Hi,
I have a couple of questions on validations and I cannot figure out what to do. Any help is appreciated.
I cannot seem to control the order of the error messages when they are display on the page.
I have validates_associated attribute and it does validate the individual fields but it also adds a line which says "model name is invalid". I don't want that error message since it already displays all the correct error messages.
class Recipe < ActiveRecord::Base
has_many :recipe_steps
has_many :recipe_ingredients
validates_presence_of :title, :message => "cannot be left blank"
validates_presence_of :servingsize, :message => "cannot be left blank"
validates_presence_of :cookingtime, :message => "cannot be left blank"
validates_numericality_of :cuisine_type_id, :greater_than => 0, :message => "Please select a cuisine type"
validates_numericality_of :recipe_level_id, :greater_than => 0, :message => "Please select a recipe level"
validates_associated :recipe_ingredients
validates_associated :recipe_steps
HUMAN_ATTRIBUTES = {
:title => "Recipe title",
:servingsize => "Serving size",
:cookingtime => "Cooking time",
:cuisine_type_id => "",
:recipe_level_id => ""
}
def self.human_attribute_name(attr)
HUMAN_ATTRIBUTES[attr.to_sym] || super
end
end
I couldn't find any good documentation or tutorials, if you could share some links that would be great.
Thanks