Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rails视图javascript未加载_Javascript_Html_Ruby On Rails_Ruby_Coffeescript - Fatal编程技术网

Rails视图javascript未加载

Rails视图javascript未加载,javascript,html,ruby-on-rails,ruby,coffeescript,Javascript,Html,Ruby On Rails,Ruby,Coffeescript,我目前正试图使用js在c9上为我的rails应用程序编写一个测试,但js似乎没有加载到视图文件中。有人能告诉我出了什么问题或建议解决方法吗 包含测验开始的主页: <div class = "signinstyle"> <div class = "row"> <div id="wrapAll"> <div id="wrapper"> <img id="logo" src="img

我目前正试图使用js在c9上为我的rails应用程序编写一个测试,但js似乎没有加载到视图文件中。有人能告诉我出了什么问题或建议解决方法吗

包含测验开始的主页:

<div class = "signinstyle">
  <div class = "row">


    <div id="wrapAll">
        <div id="wrapper">

                <img id="logo" src="img/geek.png" alt=""><br>
                 <h1>Help us recommend a <span>Course</span></h1>

                 </div>
                 </div>
                 </div>
                 <div class ="row">
                    <div id="wrapper">
                <input class="start-btn" type="submit" value="Start!" onclick="redirect('ques.html')">

        </div>
    </div>



</div>


    <script src='main.js' type='text/javascript'></script>


帮我们推荐一门课程
从js中引出问题的视图:

    <!--Functionality of recommender?? --> 
    <% provide(:title, '') %>


    <!--containers for design/layout --> 
    <div class = "signinstyle">
      <div class = "row">
        <!--Page information --> 


        <div id="wrapAll">
            <div id="wrapper">

                    <div class="ques-wrap">
                        <h2 id="ques">This is question</h2>
                        <input class="btn1" type="submit" id="opt1" value="Option 1" onclick="optionClick('1')">
                        <input class="btn2" type="submit" id="opt2" value="Option 2" onclick="optionClick('0')">
                        <div class="clear"></div>

                </div>
            </div>
        </div>

        </div>
        </div>
        <script src='main.js' type='text/javascript'></script>
        <script type='text/javascript'>
            window.onload = function(){
              generate();
            };
        </script>

这是个问题
window.onload=函数(){
生成();
};
应用程序布局视图:


|大学2选择
正确%>
正确%>




main.js文件:

//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require chartkick
//= require turbolinks
//= require_tree .



var data = {
    questions: [{
            question: "Which interests you most?",
            options: [ "Medicine" , "Drama" ]
        }, {
            question: "Which interests you most?",
            options: [ "Biology" , "Music" ]
        }, {
            question: "Which interests you most?",
            options: [ "Chemistry" , "Sculpting" ]
        }, {
            question: "Which interests you most?",
            options: [ "Psychology" , "Design" ]
        }, {
            question: "Which interests you most",
            options: [ "Animals" , "Art" ]
        }, {
            question: "Which interests you most",
            options: [ "Maths" , "Outdoors" ]
        }, {
            question: "Which interests you most?",
            options: [ "Engineering" , "English" ]
        }, {
            question: "Which interests you most?",
            options: [ "Computing" , "Ancient history" ]
        }, {
            question: "Which interests you most?",
            options: [ "Physics ", "Dance" ]
        }, {
            question: "Which interests you most?",
            options: [ "Geography" , "Fashion" ]
        }, {
            question: "Which interests you most?",
            options: [ "History" , "Dentistry" ]
        }, {
            question: "Which interests you most?",
            options: [ "Debating" , "Photography" ]
        }, {
            question: "Which interests you most?",
            options: [ "Creative Writing" , "Accounting" ]
        }, {
            question: "Which interests you most?",
            options: [ "Archaeology " , "Hospitality" ]
        }, {
            question: "Which interests you most?",
            options: [ "Construction " , "Teaching" ]
        }, {
            question: "Which interests you most?",
            options: [ "Graphics" , "Philosophy" ]
        }, {
            question: "Which interests you most?",
            options: [ "Business" , "Drawing" ]
        }, {
            question: "Which interests you most?",
            options: [ "Nutrition" , "Politics" ]
        }, {
            question: "Which interests you most?",
            options: [ "Sports" , "IT" ]
        }, {
            question: "Which interests you most?",
            options: [ "Economics" , "Languages" ]
        },],
    geeks: [
        {
            name: "Linus Torvalds",
            info: "Linus Benedict Torvalds is a Finnish American software engineer, who was the principal force behind the development of the Linux kernel that became the most popular kernel for operating systems."
        }, {
            name: "Dennis Ritchie",
            info: "Dennis MacAlistair Ritchie was an American computer scientist. He created the C programming language and, with long-time colleague Ken Thompson, the Unix operating system."
        }, {
            name: "Bill Gates",
            info: "William Henry 'Bill' Gates III is an American business magnate, philanthropist, investor, computer programmer, and inventor."
        }, {
            name: "Steve Jobs",
            info: "Steven Paul 'Steve' Jobs was an American entrepreneur, marketer, and inventor, who was the cofounder, chairman, and CEO of Apple Inc."
        }, {
            name: "Steve Wozniak",
            info: "Stephen Gary 'Steve' Wozniak, known as 'Woz', is an American inventor, electronics engineer, and computer programmer who co-founded Apple Computer with Steve Jobs and Ronald Wayne."
        }, {
            name: "Mark Zuckerberg",
            info: "Mark Elliot Zuckerberg is an American computer programmer and Internet entrepreneur. He is best known as one of five co-founders of the social networking website Facebook. Zuckerberg is the chairman and chief executive of Facebook, Inc."
        }, {
            name: "Tim Berners-Lee",
            info: "Sir Timothy John 'Tim' Berners-Lee, also known as TimBL, is an English computer scientist, best known as the inventor of the World Wide Web."
        }]
};

var qIndex = 0,
    index = 0,
    aString = "",
    maxQ = 20,
    q = document.getElementById('ques'),
    opt1 = document.getElementById('opt1'),
    opt2 = document.getElementById('opt2');

function generate(){
    q.innerHTML= data.questions[qIndex].question;
    opt1.value= data.questions[qIndex].options[0];
    opt2.value= data.questions[qIndex].options[1];
}

function optionClick(ans) {
    if(qIndex%2==0){
        aString+=ans;
        index++;
    }
    qIndex++;
    if(qIndex == maxQ){
        redirect( "result.html?" + generateResult(aString) );
    } else{
        generate();
    }
}

function generateResult(answers) {
    if( answers=="11110" || answers=="11000" || answers=="01000" ) return 0;
    else if( answers=="11111" || answers=="01010" ) return 1;
    else if( answers=="10011" || answers=="00111" || answers=="00101" ) return 2;
    else if( answers=="10100" || answers=="00110" || answers=="00000" ) return 3;
    else if( answers=="10101" ) return 4;
    else if( answers=="11101" || answers=="10010" || answers=="01111" ) return 5;
    else return 6;
}

function showResult() {
    var id = window.location.search.substring(1);
    var Geeks = data.geeks;
    var totalGeeks = Object.keys(Geeks).length - 1;
    if( id > totalGeeks || id < 0 || !id ) redirect("index.html");
    var name = document.getElementById("geekName");
    var info = document.getElementById("geekInfo");
    var img = document.getElementById("geekImage");
    name.innerHTML = Geeks[id].name;
    img.src = "img/"+id+".png";
    img.alt =Geeks[id].name;
    info.innerHTML = Geeks[id].info;
}

function redirect(url) {
    window.location = url;
}
/=需要jquery
//=需要jquery\u ujs
//=需要引导
//=需要chartkick
//=需要涡轮链路
//=需要一棵树。
风险值数据={
问题:[{
问题:“你最感兴趣的是什么?”,
选项:[“医学”、“戏剧”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“生物学”、“音乐”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“化学”、“雕刻”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“心理学”、“设计”]
}, {
问题:“你最感兴趣的是什么”,
选项:[“动物”、“艺术”]
}, {
问题:“你最感兴趣的是什么”,
选项:[“数学”、“户外”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“工程”、“英语”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“计算”、“古代历史”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“物理”、“舞蹈”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“地理”、“时尚”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“历史”、“牙科”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“辩论”、“摄影”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“创造性写作”、“会计”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“考古学”、“酒店业”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“施工”、“教学”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“图形”、“哲学”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“业务”、“图纸”]
}, {
问题:“你最感兴趣的是什么?”,
备选案文:[“营养”、“政治”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“体育”、“IT”]
}, {
问题:“你最感兴趣的是什么?”,
选项:[“经济学”、“语言”]
},],
极客:[
{
名称:“莱纳斯·托瓦尔兹”,
信息:“Linus Benedict Torvalds是一名芬兰裔美国软件工程师,他是开发Linux内核的主要力量,Linux内核成为最流行的操作系统内核。”
}, {
姓名:“丹尼斯·里奇”,
信息:“丹尼斯·麦卡里斯泰尔·里奇是一位美国计算机科学家。他创造了C编程语言,并与长期的同事肯·汤普森一起开发了Unix操作系统。”
}, {
姓名:“比尔·盖茨”,
信息:“威廉·亨利‘比尔’盖茨三世是美国商业巨头、慈善家、投资者、计算机程序员和发明家。”
}, {
姓名:“史蒂夫·乔布斯”,
信息:“史蒂文·保罗·乔布斯是一位美国企业家、营销者和发明家,他是苹果公司的联合创始人、董事长和首席执行官。”
}, {
姓名:“史蒂夫·沃兹尼亚克”,
信息:“斯蒂芬·加里·史蒂夫·沃兹尼亚克(Stephen Gary’Steve’Wozniak)是美国发明家、电子工程师和计算机程序员,与史蒂夫·乔布斯和罗纳德·韦恩共同创建了苹果电脑公司。”
}, {
姓名:“马克·扎克伯格”,
信息:“马克·埃利奥特·扎克伯格是美国计算机程序员和互联网企业家。他是社交网站Facebook的五位联合创始人之一。扎克伯格是Facebook,Inc.的董事长兼首席执行官。”
}, {
姓名:“Tim Berners Lee”,
信息:“蒂莫西·约翰·伯纳斯·李爵士(Sir Timothy John’Tim’Berners Lee),又名TimBL,是英国计算机科学家,以万维网的发明者而闻名。”
}]
};
var qIndex=0,
指数=0,
aString=“”,
maxQ=20,
q=document.getElementById('ques'),
opt1=document.getElementById('opt1'),
opt2=document.getElementById('opt2');
函数生成(){
q、 innerHTML=data.questions[qIndex].question;
opt1.value=data.questions[qIndex]。选项[0];
opt2.value=data.questions[qIndex]。选项[1];
}
功能选项单击(ans){
如果(qIndex%2==0){
aString+=ans;
索引++;
}
qIndex++;
if(qIndex==maxQ){
重定向(“result.html?”+generateResult(aString));
}否则{
生成();
}
}
函数生成器结果(答案){
if(answers==“11110”| | answers==“11000”| | answers==“01000”)返回0;
else if(answers==“11111”| ans
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require chartkick
//= require turbolinks
//= require_tree .



var data = {
    questions: [{
            question: "Which interests you most?",
            options: [ "Medicine" , "Drama" ]
        }, {
            question: "Which interests you most?",
            options: [ "Biology" , "Music" ]
        }, {
            question: "Which interests you most?",
            options: [ "Chemistry" , "Sculpting" ]
        }, {
            question: "Which interests you most?",
            options: [ "Psychology" , "Design" ]
        }, {
            question: "Which interests you most",
            options: [ "Animals" , "Art" ]
        }, {
            question: "Which interests you most",
            options: [ "Maths" , "Outdoors" ]
        }, {
            question: "Which interests you most?",
            options: [ "Engineering" , "English" ]
        }, {
            question: "Which interests you most?",
            options: [ "Computing" , "Ancient history" ]
        }, {
            question: "Which interests you most?",
            options: [ "Physics ", "Dance" ]
        }, {
            question: "Which interests you most?",
            options: [ "Geography" , "Fashion" ]
        }, {
            question: "Which interests you most?",
            options: [ "History" , "Dentistry" ]
        }, {
            question: "Which interests you most?",
            options: [ "Debating" , "Photography" ]
        }, {
            question: "Which interests you most?",
            options: [ "Creative Writing" , "Accounting" ]
        }, {
            question: "Which interests you most?",
            options: [ "Archaeology " , "Hospitality" ]
        }, {
            question: "Which interests you most?",
            options: [ "Construction " , "Teaching" ]
        }, {
            question: "Which interests you most?",
            options: [ "Graphics" , "Philosophy" ]
        }, {
            question: "Which interests you most?",
            options: [ "Business" , "Drawing" ]
        }, {
            question: "Which interests you most?",
            options: [ "Nutrition" , "Politics" ]
        }, {
            question: "Which interests you most?",
            options: [ "Sports" , "IT" ]
        }, {
            question: "Which interests you most?",
            options: [ "Economics" , "Languages" ]
        },],
    geeks: [
        {
            name: "Linus Torvalds",
            info: "Linus Benedict Torvalds is a Finnish American software engineer, who was the principal force behind the development of the Linux kernel that became the most popular kernel for operating systems."
        }, {
            name: "Dennis Ritchie",
            info: "Dennis MacAlistair Ritchie was an American computer scientist. He created the C programming language and, with long-time colleague Ken Thompson, the Unix operating system."
        }, {
            name: "Bill Gates",
            info: "William Henry 'Bill' Gates III is an American business magnate, philanthropist, investor, computer programmer, and inventor."
        }, {
            name: "Steve Jobs",
            info: "Steven Paul 'Steve' Jobs was an American entrepreneur, marketer, and inventor, who was the cofounder, chairman, and CEO of Apple Inc."
        }, {
            name: "Steve Wozniak",
            info: "Stephen Gary 'Steve' Wozniak, known as 'Woz', is an American inventor, electronics engineer, and computer programmer who co-founded Apple Computer with Steve Jobs and Ronald Wayne."
        }, {
            name: "Mark Zuckerberg",
            info: "Mark Elliot Zuckerberg is an American computer programmer and Internet entrepreneur. He is best known as one of five co-founders of the social networking website Facebook. Zuckerberg is the chairman and chief executive of Facebook, Inc."
        }, {
            name: "Tim Berners-Lee",
            info: "Sir Timothy John 'Tim' Berners-Lee, also known as TimBL, is an English computer scientist, best known as the inventor of the World Wide Web."
        }]
};

var qIndex = 0,
    index = 0,
    aString = "",
    maxQ = 20,
    q = document.getElementById('ques'),
    opt1 = document.getElementById('opt1'),
    opt2 = document.getElementById('opt2');

function generate(){
    q.innerHTML= data.questions[qIndex].question;
    opt1.value= data.questions[qIndex].options[0];
    opt2.value= data.questions[qIndex].options[1];
}

function optionClick(ans) {
    if(qIndex%2==0){
        aString+=ans;
        index++;
    }
    qIndex++;
    if(qIndex == maxQ){
        redirect( "result.html?" + generateResult(aString) );
    } else{
        generate();
    }
}

function generateResult(answers) {
    if( answers=="11110" || answers=="11000" || answers=="01000" ) return 0;
    else if( answers=="11111" || answers=="01010" ) return 1;
    else if( answers=="10011" || answers=="00111" || answers=="00101" ) return 2;
    else if( answers=="10100" || answers=="00110" || answers=="00000" ) return 3;
    else if( answers=="10101" ) return 4;
    else if( answers=="11101" || answers=="10010" || answers=="01111" ) return 5;
    else return 6;
}

function showResult() {
    var id = window.location.search.substring(1);
    var Geeks = data.geeks;
    var totalGeeks = Object.keys(Geeks).length - 1;
    if( id > totalGeeks || id < 0 || !id ) redirect("index.html");
    var name = document.getElementById("geekName");
    var info = document.getElementById("geekInfo");
    var img = document.getElementById("geekImage");
    name.innerHTML = Geeks[id].name;
    img.src = "img/"+id+".png";
    img.alt =Geeks[id].name;
    info.innerHTML = Geeks[id].info;
}

function redirect(url) {
    window.location = url;
}
<%= javascript_include_tag 'application', 'main', 'data-turbolinks-track' => true  %>
 <script src='main.js' type='text/javascript'></script>
<%= javascript_include_tag 'main'  %>