title: What is better - use ajax calls from assets/javascript/*.js or *.js.erb views?
body: <p>I'm writing an admin service from network communicator using rails. </p>
  
  <p>So my problem:
  User clicks a button -> groups user sees network groups -> user chooses some group -> user sees IP addresses. I have two forms on the page and I need to send data to the page two times without the page reloading. </p>
  
  <p>The first server response is a list of network group names.</p>
  
  <p>The second server response is a list of IP addresses in one of the groups.</p>
  
  <p>Question:</p>
  
  <p>Which is better to do after user request:</p>
  
  <ol>
  <li><p>JS.ERB way</p>
  
  <p>Get data, put it into views/some_file.js.erb, write something like "respond_to{ |format| format.js }" in controller. Expected result: browser recieve js, js code run on client, js code append data into table on page.</p></li>
  <li><p>JS with ajax in assets/javascript way</p>
  
  <p>Send data in json format to client. js code make ajax call to server, bowser recieve json-data form server, js append data into table on page.</p></li>
  </ol>
  
  <p>Please, explain the advantages and disadvantages of both ways. Thanks.</p>