In my view I save an array of hashes in a hidden field
<div>
<%= hidden_field_tag :data_filtered, :value => @data_filtered %>
</div>
My javascript is
$(document).ready(function(){
freezeTopRow($('#dataTable'));
$("#export").click(function(){
var data1 = $("#data_filtered").val()
$.ajax({
type: "POST",
url: "export",
dataType: 'json',
data: {data_filtered: data1}
});
});
});
My controller is
def export
CSV.open("data.csv", "wb") do |csv|
csv << params[:data_filtered].first.keys
@data_filtered.each do |hash|
csv << hash.values
end
end
end
When I view params[:data_filtered] after it has been returned to the controller i see a string:
"{:value=>[{"a"=>nil, "b"=>nil, "c"=>0}]}"
But I want it to be in its original form of (array of hashes, in this case just 1 hash) half the problem is the :value. I don't want that to be stored and I don't know how to parse that to get just the array. Basically i want
[{"a"=>nil, "b"=>nil, "c"=>0]
@data_filteredin your view? Is it a Hash perhaps?to_sand that's not meant to be easily parsed. If you use JSON then parsing becomes easier.