title: Call controller method with rails-Ajax?
body: <p>I am trying to execute a Ruby method in my application_controller.rb from a button in my view.
  In a post yesterday, someone told me to use an Ajax call to do so because, without it, would just run on page load.</p>
  
  <p>I'm very new to this and I have a hard time understanding it.</p>
  
  <p>I installed the rails-Ajax gem, and it is added to my Gem file.</p>
  
  <p>I followed "<a href="http://rails-ajax.sourceforge.net/wiki/index.php/Main_Page" rel="nofollow">Integrate Ajax capabilities to Rails websites with history, bookmarking, partial refreshes, Rails flashes, user callbacks, scripts execution, redirections.</a>" untill step 5.</p>
  
  <p>I just don't know what to do it next.</p>
  
  <p>Here is my current configuration. The method only runs on page load:</p>
  
  <p>My view:</p>
  
  <pre><code>&lt;td&gt;&lt;button type="button" onclick="executeit()" class="btn btn- default"&gt;executer&lt;/button&gt;&lt;/td&gt;
  
  &lt;script&gt;
  function executeit() {
   var selectingCommand = document.getElementById("CommandSelect");
   var selectedCommand = selectingCommand.options[selectingCommand.selectedIndex].text;
   var selectingServer = document.getElementById("serverlist");
   var selectedServer = selectingServer.options[selectingServer.selectedIndex].text;
   var username=document.getElementById("login").text;
   var password=document.getElementById("password").text;
  
  
  
  &lt;%execute%&gt;;
  
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>My method in application_controller.rb :</p>
  
  <pre><code>def execute
    require 'rubygems'
    require 'net/ssh'
  
    @hostname = "smtlmon02"
    @username = "test"
    @password = "1234"
    @cmd = "ls -al"
    @cmd2 = "sudo su - -c 'ls;date'"
    @cmd3 = "ls -alrt"
  
    ssh = Net::SSH.start(@hostname, @username, :password =&gt; @password)
    res = ssh.exec!(@cmd)
    res2 = ssh.exec!(@cmd2)
  
    ssh.close
    puts res2
  
  end
  </code></pre>
  
  <p>It would be fantastic if anyone could explain how to do it!</p>