[英]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.