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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tim Shaffer
2011-May-02 15:16 UTC
Re: copy the content of javascipt variable to ruby variable
You can''t do this directly. JavaScript runs on the client side in the user''s browser. Ruby/Rails runs on the server side. What are you actually trying to accomplish? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Costas C.j
2011-May-02 15:43 UTC
Re: copy the content of javascipt variable to ruby variable
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 -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tim Shaffer
2011-May-02 18:52 UTC
Re: copy the content of javascipt variable to ruby variable
The send_data function is useful when you have a bunch of data on the server that needs to be streamed to the client. Since your data is stored in a JavaScript variable (already on the client), 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 efficient. 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 is already on the client. I found this function which will create CSV from JSON: http://www.zachhunter.com/2010/11/download-json-to-csv-using-javascript/ It may not fit your needs exactly, but the relevant line is the following: window.open( "data:text/csv;charset=utf-8," + escape(str)) As long as the str variable contains comma-separated data, this should work fine. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.