简体   繁体   English

Rails没有在app / assets / javascripts下注册javascript文件

[英]rails not registering javascript files under app/assets/javascripts

I'm currently trying to integrate d3 with my rails app. 我目前正在尝试将d3与我的rails应用集成。 After installing the d3-rails gem, I came across this tutorial on d3. 安装d3-rails gem之后,我在d3上遇到了本教程 Somewhere in the tutorial, the below code is provided 在本教程的某个地方,提供了以下代码

<meta charset="utf-8">
<style>

.chart div {
  font: 10px sans-serif;
  background-color: steelblue;
  text-align: right;
  padding: 3px;
  margin: 1px;
  color: white;
}

</style>
<div class="chart"></div>
<script>

var data = [4, 8, 15, 16, 23, 42];

var x = d3.scale.linear()
    .domain([0, d3.max(data)])
    .range([0, 420]);

d3.select(".chart")
  .selectAll("div")
    .data(data)
  .enter().append("div")
    .style("width", function(d) { return x(d) + "px"; })
    .text(function(d) { return d; });

</script>

If I were to include the above code as it is into my new.html.erb file, the chart will show. 如果将上述代码原样包含在我的new.html.erb文件中,将显示该图表。

I then created a new graph.js fiel under app/assets/javascripts and decided to put everything between the <script> </script > tag inside graph.js . 然后,我在app / assets / javascripts下创建了一个新的graph.js文件,并决定将所有内容放在graph.js内部的<script> </script >标记之间 Now when I open up new.html.erb , the chart will not show anymore. 现在,当我打开new.html.erb时 ,该图表将不再显示。

Am I doing something wrong here that's causing rails to not recognize graph.js ? 我在这里做错什么导致Rails无法识别graph.js吗?

Did you compile the assets? 您是否汇编了资产?

You'll need to run: 您需要运行:

rake asset:precompile

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails应用程序未使用资产加载javascripts文件 - Rails application not loading javascripts files using assets 为什么将app / assets / javascripts中的coffee文件加载到所有文件中? - Why coffee files in app/assets/javascripts are loaded in all the files? Heroku和Rails 4:Heroku在资产/ JavaScripts下找不到我的嵌套文件夹 - Heroku and Rails 4: Heroku isn't finding my nested folder under assets/javascripts 资产中的Javascript未在Rails应用中加载 - Javascript in assets not loading in Rails app `application.js`不再包括Rails 3.1应用程序的app / assets / javascripts中的所有脚本 - `application.js` no longer including all scripts in app/assets/javascripts for Rails 3.1 app 在Ruby on Rails应用的生产部署中缺少Javascript资产,在WEBrick下一切正常 - Missing Javascript assets on production deployment of Ruby on Rails app, all is fine under WEBrick Rails递归地包含javascripts资源文件夹 - Rails include javascripts assets folder recursively Rails 4:application.js中的“ // = require_tree”在/ app / assets / javascripts中不包含我的js文件 - Rails 4: “//= require_tree .” in application.js doesn't include my js file in /app/assets/javascripts 将JS代码迁移到Rails应用程序中的资产/ JavaScript之后,会话变量不再被识别 - session variable is not recognized anymore after migrating js code to assets/javascripts in rails app 如何从Rails的“查看”页面中的/ app / assets / javascripts文件夹中调用JS脚本? - How can I call upon a JS script in my /app/assets/javascripts folder from a View page in Rails?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM