Hi guys , i am currently trying to display my errors that i added to user object inside the controller simultaneously with my validation inside the model.
like if maybe i have an error in my controller it display it immediately then return and without displaying the errors inside the model, i know that it has to return if my errors are finished counting and display all of them not one by one.
i even wrote a validation method that should check the validations inside the model and save them to my object then the display error method can display all the errors including the one's that was found in the model.
my controllers methods are like this
def info
if @user.firstname != "" && @user.lastname != "" && @user.id_number != "" && @user.email != ""
@user.errors.add_to_base("Password can't be blank")
end
end
def validations()
@errors = User.check_validations
end
def display(template_to_render)
if @user.errors.count >= 1
render :action => template_to_render
end
end
Then my method in the model is as follows
def self.check_validations validates_presence_of :firstname, :lastname, :date_of_birth, :if => Proc.new { |o| o.force_update? || o.profile_confirmed? } end
then i want to add all the errors of validations method to the @user.errors.to_base errors and display them all.
so i was wondering if there is any method maybe that i can use to check the method inside the model and add all those errors to the @user object before it can display on the view.