Is it possible to assign the params hash with javascript variables in the views side. because i would be doing a complicated structure in my params hash that involves nesting and arrays.
-
Please clarify what you mean. The view is a result of the controller, where the params hash lives, so doing it the way you're asking isn't really possible.Farski– Farski2012-05-06 17:13:48 +00:00Commented May 6, 2012 at 17:13
-
I tried setting variables to the params variable in the view side. My question if i can set it with javascript variables. though i have the feeling its not possibleJude Calimbas– Jude Calimbas2012-05-07 06:53:53 +00:00Commented May 7, 2012 at 6:53
2 Answers
You can post JSON data to the rails server and Rails will make it available in params hash, provided the JSON response data has the correct headers. Refer this thread and this thread for more details.
Comments
The only way I can think of is to use JS to add new fields to your form, giving them IDs and names adhering to how Rails will parse the elements' names into params when the form is submitted (something along the lines of id=model_assoc_attributes_N_attr and name=model[assoc_attributes][N][attr], which I think is the case when Model accepts_nested_attributes_for Assoc).