views:

25

answers:

0

Hi, I'm pretty new at rails and have an app where the user has to "turn-on" a script. I have this code in the view:

<% if @robot.thread_status == "" || @robot.thread_status == nil %>
      <b>Status: <font color ="red">NOT MONITORING</font></b> 
      <br>
      <% if @robot.recipients.present? %>
      <%= link_to 'Start monitoring this room now', start_robot_path(@robot), :style => "color:green;" %>
      <% else %>
      Create at least one recipient to begin monitoring this room.
      <% end %>
    <% else %>
      <b>Current Status: <font color ="green">ACTIVE</font></b>
      <br><%= link_to 'Stop monitoring this room', stop_robot_path(@robot), :style => "color:red;" %>
    <% end %>

This is what's in the controller:

if BUNNY.client.status == :connected
        BUNNY.publish(hash.to_json)
        flash[:notice] = 'Instruction to start robot sent successfully. Please give our systems about 45 seconds to start monitoring your robot. '
        format.html { redirect_to(@robot) }
      else
        flash[:notice] = 'Unable to send instruction to start bot.'
        format.html { redirect_to(@robot) }
      end

The redirect however happens so fast, that unless the user refreshes their browser they don't see that the script has been activated.

I know there's probably a jqueryish way to solve this, but I'm so new that road looks scary. I was thinking if I could just add a delay to the controller maybe that would work?

How would you solve this in the easiest way? I'm open to using a jquery solution - but I'd prefer it to be pretty simple if I do.

Thanks.