Topic: Ajax + Conditional Execution & Conditional Confirmation

I am struggling with the following ... I have an Ajax request (not a form) that gets fired, but I want to force the user to accept something before the request fires. I know that I can just add a confirm message but I want it to be explicit, I want them to click a check box before the Ajax request will execute, if they do NOT accept (or click) the checkbox I want to display a message saying they must do so. I cannot figure out how to add a condition to the confirmation message.

Any ideas?

Not exactly what I want.

I agree to the terms & conditions!
<%= check_box_tag :confirm, '', false %>

<%= button_to_remote 'Start',
   :url => {:action => :start},
   :condition => "$('confirm').checked",
   :confirm => "alert($('confirm').checked)" %>

Doesn't work.

I agree to the terms & conditions!
<%= check_box_tag :confirm, '', false %>

<%= button_to_remote 'Start',
   :url => {:action => :start},
   :condition => "$('confirm').checked",
   :confirm => "if ($('confirm').checked) {alert('Please accept first!')}" %>

Re: Ajax + Conditional Execution & Conditional Confirmation

You have two choices, JavaScript on the client side,  or let Rails do it. 

I would use jQuery UI's dialog to throw up a modal dialog.

If you don't want to mess with JavaScript that much,  you could just do it with Rails,  i.e.

<% form_remote_tag '/controller/start' 
  <span id='question'>Please Check</span>
  <% = check_box_tag 'confirm' %>
  <%= button_to_remote, 'Start' ,: url=> {:action=>:start}  
<% end>

then in your controller

def start
  if params[:confirm]
    startit
  else
    render(:update) do |page|
      page[:question].replace_html 'Check DAMN IT!'
    end
end
Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.