jeudi 2 juillet 2015

Javascript Alert in Rails app - checkbox for params hash

I'm working on a Rails app that's using an external api for authentication. If the the same login credentials are used simultaneously the app has to alert the second user that there's already a session in progress. This needs to be a JavaScript alert with an 'ok' box, and the return has to be passed to the api as a flag to kill the first session.

I've got ideas for parts of it, but it's not coming together.

A hidden input in the login form that's triggered by the alert box?

I also tried this for the alert, but I'm unsure of how to pass 'msg' into the JavaScript, and this doesn't even address the params issue.

login_controller.rb

  elsif body['ValidationMessage'] == 'OtherSessionActive'
    flash[:alert] = auth_config['session_alert']
    redirect_to login_path and return
  else

login.html.erb

  <div id='flash'>
    <% flash.each do |name, msg| %>
        <% if name == :alert %>
            <script>
                alert(#{msg})
            </script>
        <% else %>
            <%= content_tag :div, msg, :id => "flash_#{name}" %>
        <% end %>
    <% end %>
  </div>

Any ideas would be appreciated.

Aucun commentaire:

Enregistrer un commentaire