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:
<%= form_for(@device) do |f| %>
.
.
.
<%= if click? ( f.submit "Commit Entries", class: "btn btn-primary" ) == true %>
<%= @device.lastChangedBy = request.remote_ip %>
<% end %>
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:
<%= button_to "Commit Entries", action: "setIp" %>
and then in DevicesController & in the helper.rb (because I wasn't sure where it would call the method) I made a simple method:
def setIp
Device.find(params[:id])
@device.lastChangedBy = request.remote_ip
end
but I am completely lost. Could someone please help me. It would be amazing if you were specific!