简体   繁体   中英

What's the most efficient way to serve external data (tsv or json) to Ruby on Rails?

d3 allows to load external data into javascript to generate SVG data visualization. But working with Rails (4.0) is tricky because I can't get an external data file, like a .tsv or a .json served so that the javascript can pull the data. It's not practical to add it manually to the js file, as an arrow or something, because of data quantity. But is not easy to find a solution to serve the static file either. I was trying to make the browser read the .tsv and then set the javascript to read from the URL, but no luck.

I have my javascripts in the right place (it's served in the browser) : app/assets/javascripts/data.js and I'm trying to get it with : d3.tsv("data.tsv", function(error, data) {...

thanks!

IF you put

config.serve_static_assets = true

In your production.rb your rails app will serve assets out of you public folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM