初学者栏/ javascript问题:
假设我在一个带有Circle
操作/视图的Rails 3.1应用程序中有一个简单的show
模型。每个Circle
都有一个名为:radius
的属性 - 一个整数值。
当我通过Circle
文件查看show.html.erb
时,我想要一个非常简单的processing.js草图来接收圆的半径并在页面上绘制圆圈。通过将文件保存在assets/javascripts
文件夹中,我已经在我的应用中包含了processing.js。
我的简单processing.js草图位于名为circle.js
的文件中。其内容如下:
// Setup the Processing Canvas
void setup(){
size( 200, 200 );
strokeWeight( 10 );
frameRate( 15 );
X = width / 2;
Y = height / 2;
radius = 10;
}
// Main draw loop
void draw(){
// Fill canvas grey
background( 100 );
// Set stroke-color white
stroke(255);
// Draw circle
ellipse( X, Y, radius, radius );
}
circle.js
文件在视图文件夹或资产管道中的位置? circle.js.erb
?答案 0 :(得分:2)
您可以将circle.js放入app / assets / javascripts。它不需要被称为circle.js.erb,但它可能是。