title: Submit Button Calling A Method
body: <p>I'm new to Ruby on Rails and I'm trying to update a device attribute (lastChangedBy) that will set its value to the user's IP address whenever the submit button is clicked. I wanted to do something like: </p>
  
  <pre><code> &lt;%= form_for(@device) do |f| %&gt;
   .
   .
   .
   &lt;%= if click? ( f.submit "Commit Entries", class: "btn btn-primary" ) == true %&gt;    
        &lt;%= @device.lastChangedBy = request.remote_ip %&gt;
   &lt;% end %&gt;
  </code></pre>
  
  <p>but I don't think that's possible. I'm looking into using "button_to" but after searching online I am extremely confused to how to use it. I tried doing something like:</p>
  
  <pre><code> &lt;%= button_to "Commit Entries", action: "setIp" %&gt;
  </code></pre>
  
  <p>and then in DevicesController &amp; in the helper.rb (because I wasn't sure where it would call the method) I made a simple method:</p>
  
  <pre><code> def setIp
        Device.find(params[:id])
    @device.lastChangedBy = request.remote_ip
   end
  </code></pre>
  
  <p>but I am completely lost. Could someone please help me. It would be amazing if you were specific!</p>