I am developing an admin service on Rails that communicates with a network communicator.
Here is my challenge: When a user clicks a button, they are presented with network groups to choose from. Once the user selects a group, they should be able to see the associated IP addresses. There are two forms on the page, and I need to send data to the page twice without causing it to reload.
The first server response provides a list of network group names.
The second server response displays a list of IP addresses within the selected group.
Now, here's the question:
What is the best approach to take after a user makes a request?
Using JS.ERB
This involves getting the data, putting it into views/some_file.js.erb, and including "respond_to{ |format| format.js }" in the controller. The expected outcome is for the browser to receive JavaScript, run the code on the client side, and then append the data into a table on the page.
Utilizing Ajax with JavaScript in the assets/javascript folder
In this scenario, data is sent to the client in JSON format. JavaScript code then makes an Ajax call to the server, receives the JSON data, and appends it into the table on the page.
I would appreciate an explanation detailing the advantages and disadvantages of each method. Thank you.