1

I am upgrading a app to rails 3.0, from rails 2.3, I upgraded the clearance gem (gem 'clearance', '1.0.0.rc2') and it seems that sign_out needs to be method delete.

I updated my sign out to be:

<%= link_to 'SignOut', sign_out_path, :method => "delete" %><

Which translates into:

<a href="/logout" data-method="delete" rel="nofollow">Logout</a>

But when I look at the server log, it says:

Started GET "/sign_out?timeout=true" for 127.0.0.1 at 2012-10-03 20:28:38 -0400
User Load '44c84e19c75fa993029ca68b4f32019d2a56ab22' LIMIT 1
ActionController::RoutingError (No route matches "/sign_out"):

Rake routes shows:

sign_out DELETE /sign_out(.:format) {:action=>"destroy", :controller=>"clearance/sessions"}

Any ideas what could be wrong?

On a related note, I have a auto logout after 3 hours that will not work either, I dont know how to do method = delete from javascript...?

function logout()
{
  location.href='/sign_out?timeout=true';
}

<% if current_user != nil %>
// 3 hours of inactivity log them out
var t= setTimeout("logout()",10800000);
<% end %>
Joelio
  • 4,621
  • 6
  • 44
  • 80
  • The code looks fine to me at first glance, but your server log clearly shows it is doing a GET. So, this is not an answer, but to get over the hump, you might try changing it from an href to a proper submit type input. Your problem is probably with the href, not your route. Also, this is two questions. You should remove the 2nd question and ask it separately. – pduey Oct 04 '12 at 22:13
  • Thanks pdue, I included the 2nd part to sort of sway away the button recommendation, if I can only logout via a button, then thats no good for me. I guess I can try that to see if it does a DELETE... – Joelio Oct 04 '12 at 22:55
  • That's what I meant, try it with a button temporarily so you can isolate the real problem. Then read this http://stackoverflow.com/questions/4342083/rails-3-link-to-method-delete-not-working – pduey Oct 05 '12 at 00:00

1 Answers1

0

Ok, I found the answer, in rails 3, even the delete javascript comes from an external source. The person setting up our rails 3 setup did not include prototype or jquery, so nothing was acting on this. Configuring https://github.com/rails/jquery-ujs should do the trick!

Joelio
  • 4,621
  • 6
  • 44
  • 80