Changing link_to to button_to
In one of my rails apps, I send out email to a particular user. But, I can look at the message before it goes out. Then, at the bottom of this preview page is a link to actually send the message. I’m pretty sure that since this action is changing a boolean value on the user along with sending the email, that I should be using a button instead of a link. However, just switching the link_to to button_to won’t work because link_to uses a GET request, but button_to uses a POST request. So I need to change the button_to to use GET. The way to do that is like this:
<%= button_to "Send rejection email to #{@applicant.fullname}", {:controller => 'applicants', :action => 'send_rejection', :id => @applicant.id}, {:method => :get, :disable_with => 'Sending Email'} %>
You must separate into hashes the info for the action and the parameters for the button or it won’t work.