Copy the content of javascipt variable to ruby variable

hi. Is there any way to copy the content of a javascript variable to a
ruby variable. can you give me an example. thank you

i am using some functions from a javascript library. i want a client to
be able to download some data. the data are stored in one javascript
variable called “data”. i want to create a button to download it as CSV.
So i want the “data”, to be copied in a ruby variable, so i can use the
send_data tag.

thank you

The send_data function is useful when you have a bunch of data on the
that needs to be streamed to the client.

Since your data is stored in a JavaScript variable (already on the
using send_data means that this data will need to be posted back to the
server, then sent back to the client using send_data. Not very

Perhaps you can use some JavaScript function to convert your data then
present it to the user as CSV. Should be relatively quick since the data
already on the client.

I found this function which will create CSV from JSON:

It may not fit your needs exactly, but the relevant line is the
following: “data:text/csv;charset=utf-8,” + escape(str))

As long as the str variable contains comma-separated data, this should

You can’t do this directly. JavaScript runs on the client side in the
browser. Ruby/Rails runs on the server side.

What are you actually trying to accomplish?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs