Jeff
Jeff

Reputation: 103

Best way to post JavaScript data to Rails

What is the best way to take a serialized list in JavaScript and save it to an instance variable array(or hash) in Rails?

Upvotes: 0

Views: 2267

Answers (3)

Greg
Greg

Reputation: 31

Here are some options on how to do this:

http://www.activars.com/2009/04/13/pass-javascript-variables-to-rails-controller/

Upvotes: 1

jklina
jklina

Reputation: 3417

You could try setting a hidden field with the list values and then setup a controller action to handle the data.

Upvotes: 0

Brian Driscoll
Brian Driscoll

Reputation: 19635

Javascript code runs on the client, and your Rails code runs on the server, so there's no way to directly pass your Javascript data to Rails. Instead you'd likely have to set up a controller to specifically handle an HTTP POST with your serialized data as the payload.

Upvotes: 2

Related Questions