There's some ERB code I'd like to run on a coffeescript file. Currently I have a controller named "places", and I'm working something on its index.
I have an index.html.haml on it, and I've managed to get coffeescript going from the assets pipeline (named places.js.coffee), but I haven't found a way to make ERB code to run from it. I read that it is possible to do this if the coffeescript is in your views. I've tried to place a coffeescript file named "index.js.coffee" inside the controller's view, but it doesn't work.
The file I tried to created is: /app/views/places/index.js.coffee
Am I using the wrong name? And/If-not, where should I place the file?
I'm on rails 4.0.2 with the coffee-rails gem (4.0.1).
Thanks in advance.
EDIT:
What I'm trying to accomplish is to use erb to inject code into the js/coffee, specifically - a set of arrays which will be used to fill data in a chart.
Normally, I'd have something like this in the places.js.coffee assets file:
labelsvariable = gon.labels
jQuery ->
data = {
labels : labelsvariable,
datasets : [
{
fillColor : "rgba(220,220,220,0.5)",
strokeColor : "rgba(220,220,220,1)",
pointColor : "rgba(220,220,220,1)",
pointStrokeColor : "#fff",
data : [ 65,59,90,81,56,55,40 ]
},
...
]
}
That works, I can use some data for the chart, but then I need to do more complex things, such as populating the datasets.
I know I could replace many of those with variables themselves, just like 'labelsvariable', but my problem comes when I bring a set of arrays that is to be included where the second data group is in the JQuery. I figured I could make a loop with erb, that could go through the array, replacing the whole datasets section, dumping the appropriate code for js/coffee.
I realize I may be taking the wrong approach, but I just couldn't come up with a better idea to send the data there. Any suggestions on that regard would be appreciated.
In regards to my original question, is it possible to run erb like this in a coffee file? If so, where should the coffee-file-that-also-runs-erb be placed?
Forgive me if I sound too vague, I'm having a really hard time to explain this. Thanks.