Search code examples
javascriptjqueryruby-on-railsrubycloud9-ide

$(...).validate is not a function


I am having trouble with the JQuery validation plugin specifically actually getting the function to be recognised. I am currently using Cloud9 Ruby on Rails development base and although the code I am using seems to work on my local machine it does not work on Cloud 9.

http://ipt-dynaman.c9.io/register

$(function() {
    $("#Register").validate({
       errorElement: 'div',    
       rules: {
            Username: "required",
            password: {
            required: true,
            minlength: 6
            },
            rePassword: {
            required: true,
            minlength: 6,
            equalTo:"#password"
            },
       },
       messages: {
            Username: "Please specify a username",
            Password: {
            required: "Please specify a password",
            minlength: "Please entire at least 6 characters"
            },
            rePassword: {
            required: "Please re-enter your password",
            equalTo: "Password mismatch"
            },
       }
    });
    console.log("eqwfqewqef");
});
<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="CSS/style.css" />
    <link rel="stylesheet" type="text/css" href="CSS/SI.css" />
    <link rel="stylesheet" type="text/css" href="CSS/unsemantic-grid-responsive.css" />
    <link rel="stylesheet" href="CSS/font-awesome-4.3.0\font-awesome-4.3.0\css\font-awesome.min.css" />
    <script type="application/javascript" src="js/jquery-2.1.3.min.js"></script>
    <script type="application/javascript" src="js/rego.js"></script>
    <script src="js/jquery-validation-1.13.1/dist/jquery.validate.min.js"></script>
    <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'jquery-2.1.3.min', 'jquery.validate.min', 'rego', 'application' %>
    <%= csrf_meta_tags %>
<title>Page links</title>
</head>
    <body>
        <%= render partial: "layouts/sign_header" %>  
        <%= yield %>
    </body>
</html>

All file paths are correct (I assume) as Chrome console could only detect an error in the validate function.

Please help I am going hard as hell to get 100% for my year 12 IT project. Please tell me if I am missing any valuable info as well.


Solution

  • You are duplicating 'jquery-2.1.3.min', 'jquery.validate.min', 'rego' in both HTML and Rails. Maintain either Rails or HTML code. Good practice is to mention your Javascript and Stylesheet in application.css and application.js. And just load application file in HTML/Rails.

    Good Practice

    application.js

    //= require jquery //= require jquery.validate.min //= require rego

    application.html.erb

    <%= javascript_include_tag 'application' %>