So I have a database that I'm trying to display reports on using the Highcharts javascript library.
The issue is i have no idea how to effectively get this data from Rails into Javascript.
Simply using html data attributes doesnt scale because i have many charts and many different sets of data for each one. I need to exclude certain columns, join tables, etc.
Any ideas?
答案 0 :(得分:1)
有几种选择:
使用ActiveModelSerializers创建端点并格式化数据,例如:https://www.engineyard.com/blog/active-model-serializers
您可以创建一个 jbuilder 视图,并通过javascript ajax调用调用的端点呈现它
https://github.com/rails/jbuilder
最低功耗 Gon ,但您发送到其中的所有内容都可在HTML源代码中查看。