Question: How do I mix Ruby and Javascript in application.js

How can I get rails to process and serve application.js.erb instead of
application.js?

I want to mix Ruby and Javascript code in the file. I am building
Javascript arrays from data that i keep in a Rails model and the
arrays are static.

Create application.js.erb and put it in views/js/

then you
render :partial => ‘js/application.js.erb’, :locals => {:data =>
@your_data}

and use variable ‘data’ in your partial like

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs