开发者

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 );                    
}  
  1. How do I include the sketch into my show view as unobtrusively as possible and pass the radius value to it?
  2. Where does the circle.js file go -- in the view folder or in the asset pipeline?
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜