0

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.

2
  • 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. Commented 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 possible Commented May 7, 2012 at 6:53

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.