Skip to content

Instantly share code, notes, and snippets.

@clarkdave
Created May 12, 2013 12:56
Show Gist options
  • Save clarkdave/5563467 to your computer and use it in GitHub Desktop.
Save clarkdave/5563467 to your computer and use it in GitHub Desktop.
Log user out in Rails via JS
$('.logout').on 'click', (e) ->
link = $(e.currentTarget)
csrf_token = $('meta[name="csrf-token"]').attr('content')
form = $('<form>')
form.hide()
form.attr('method', 'post').attr('action', link.attr('href'))
$("<input type='hidden' name='authenticity_token' value='#{csrf_token}'>").appendTo(form)
$('<input name="_method" type="hidden" value="delete">').appendTo(form)
link.parent().append(form)
form.submit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment