jeudi 20 août 2020

How to validate error message before update in ruby on rails

I got the error message before save. But I can't validate the error messages before update.

      def create
        # @student = Student.new
        @student = Student.new(student_params)
        
        # @student = @student.school.build(student_params)
        if @student.valid?
          @student.save
            redirect_to students_path
            # render 'new'
        else
            render 'new'
        end
      end
    
      def edit
        @schools = School.all
        @student = Student.find(params[:id])
      end
    
      def update
        @student = Student.find(params[:id])
         if @student.valid?
          @student.update(student_params)
            redirect_to students_path
        else
          render 'edit'
        end
      end

def student_params params.require(:student).permit(:status, :email, :password, :school_id, :department_id)

end

Aucun commentaire:

Enregistrer un commentaire