I have been Googling around for an answer to this for about an hour now after trying to get it to work with what i know about rails for quite some time and decided enough was enough. On my index page i want to create a button that acts like the default 'delete' action but instead it will update a boolean value. This is my action in my controller:
def update_monitor_state
@server_monitor.paused = not @server_monitor.paused
redirect_to server_monitors_url
end
I would show you my routes but i have no idea how to get it to do what i want and i have the basic 'resources :server_monitors' after trying everyone's routes that would work for adding a new show page for their basic blog site. I just know the URI pattern should be '/server_monitors/:id(.:format)' and the controller action 'server_monitors#update_monitor_state' and i would like to call it in the views like how 'delete' is called.
<% @server_monitors.each do |monitor| %>
<tr>
<td><%= monitor.monitor_name %></td>
<td>
<% if monitor.paused %>
<%= link_to 'Start', monitor, method: :update_monitor_state %>
<% else %>
<%= link_to 'Pause', monitor, method: :update_monitor_state %>
<% end %>
</td>
<td><%= link_to 'Destroy', monitor, method: :delete %></td>
</tr>
<% end %>