Beginner question: How do I integrate processing.js with a Rails 3.1 app?
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
?
You can put circle.js into app/assets/javascripts. It doesn't need to be called circle.js.erb, but it could be.
精彩评论