To call that line of code in your controller, you can make a form which will point to an action in a controller, and that action will have something like this:
def send_mail
@task = Task.find(params[:task_id])
UserMail.task_reminder(@task).deliver
redirect_to :back
end
You'd also need to enter in your routes file that controller, like so:
post "tasks/send_mail", :to => "tasks#send_mail", :as => "send_mail"
This would be your form (very simple), which would just have a button there. You could just trigger that form on page load:
<%= form_tag("/tasks/send_mail", method: "post", url: send_mail_path) do %>
<%= hidden_field_tag :task_id, "#{@task.id}" %>
<%= submit_tag "Submit" %>
<% end %>
Hope this helps!
Try adding this to the top of your send_mail
method:
if(params.has_key?(:task_id)
redirect_to "/"
end
If it redirects you, then the params are being passed, if not, we have a problem ;)