初学者问题:如何将processing.js 与Rails 3.1 应用程序集成?
初学者 Rails/javascript 问题:
假设我在 Rails 3.1 应用程序中有一个简单的 Circle
模型,并带有 show
操作/视图。每个Circle
都有一个名为:radius
的属性 - 一个整数值。
当我通过 show.html.erb
文件查看Circle
时,我想要一个非常简单的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?
Beginner rails/javascript question:
Let's say that I have a simple Circle
model in a Rails 3.1 app with a show
action/view. Each Circle
has a property called :radius
- an integer value.
When I view the Circle
via its show.html.erb
file, I want a very simple processing.js sketch to receive the radius of the circle and draw the circle on the page. I've already included processing.js in my app by saving the file in the assets/javascripts
folder.
My simple processing.js sketch is in a file called circle.js
. Its contents are:
// 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 );
}
- How do I include the sketch into my show view as unobtrusively as possible and pass the radius value to it?
- Where does the
circle.js
file go -- in the view folder or in the asset pipeline? - Does it need to be named
circle.js.erb
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将circle.js放入app/assets/javascripts中。它不需要被称为circle.js.erb,但它可以是。
You can put circle.js into app/assets/javascripts. It doesn't need to be called circle.js.erb, but it could be.