How to pass parameters dynamically to Rails?

Asked

Viewed 742 times

0

I have a rather complex problem. I need to somehow pass parameters dynamically to params via javascript, to show/hide some fields in a report at the user’s request. Below is a representation of the screen:

Demonstração de como a UI funciona.

I have a form where the user enters with the data he wants in the search, with remote: true. Up there I have a container with a group of checkboxes, which is my problem at the moment. Below is where the results are loaded from a partial with a .js.erb file. Note that only this part reloads.

The box with the checkboxes is not part of a form, and in my mind they shouldn’t be. In Javascript, I have an event linked to each checkbox. When each is unchecked, the corresponding field in the result tables is hidden and an Hidden field is created and dynamically inserted into the form on the left. Therefore, I can send these parameters via url at Submit time and hide these fields with a conditional giving a display: None on the lines where the parameter has value 1. This works if the user performs the filtering. But if it is not done, the parameters are not sent to the URL and when paging is done, the lines that should be hidden appear.

I wonder then if there is a way to send these parameters to the hash params dynamically via AJAX, for everything to work properly with, or without filtering...

  • See also: http://answall.com/questions/9923/como-segurr-o-valor-de-um-post-entre-pagina%C3%A7%C3%A3o-no-codeigniter/9926#9926 and http://pt.overfstacklow.com/questions/12241/como-passar-vari%C3%A1veis-entre-p%C3%A1ginas-php-via-javascript (duplicates?)

1 answer

1

I’d do it this way: I would put my form wrapping everything and take out the Javascript that adds the hidden fields in the form.

Paging would be Submit buttons with the name of the page you want.

With this each time the user clicks on a new page, will submit the form and send along with the parameters the pagination you want.

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.