I'm currently working with Rails 4 and encountering an issue with the following file:
// apps/assets/javascripts/products.js.erb
var getColoursAndMaterialsData = function(onSuccess)
{
var fd = formdata();
$.post( '<%= data_products_path(:format => :json) %>', fd )
.done(function(data)
{
onSuccess(data);
});
};
When I include products.js.erb in a .html.erb file, I am faced with the error:
undefined method `data_products_path'
It seems like the routes prefix 'data_products_path' is not being pre-processed. I had assumed that by giving products.js the .erb extension, it would have prompted the pre-processor to handle it.
Interestingly, the exact same code works fine when placed within
<script type="text/javascript"></script>
tags in the .html.erb file. The relevant section of my routes.rb file has this structure:
resources :products do
collection do
post 'data'
end
end
Is there another step or configuration required for this to work correctly?