Devise: Devise destroy_user_session returns GET or DELETE in link_to

Created on 22 Dec 2015  路  3Comments  路  Source: heartcombo/devise

I have the following 2 codes on 2 different pages of the same rails project.

<%= link_to "<i class='fa fa-power-off'></i>".html_safe, destroy_user_session_path,  class: 'tip', :data => {:confirm => "You are going to be disconnected", :title => 'Logoff'}, :method => :delete %>

and

<%= link_to "Log out", destroy_user_session_path, method: :delete %>

They respectively return the following HTML

<a class="tip" data-confirm="You are going to be disconnected" data-title="Logoff" rel="nofollow" data-method="delete" href="/users/sign_out" data-original-title="" title=""><i class="fa fa-power-off"></i></a>

and

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

While the second one is working fine, the first one fails as it is looking for a GET /users/sign_out that does not exist.

Devise 3.5.3
Rails 4.2.5
Ruby 2.2.3

Most helpful comment

Can you double check if the rails ujs javascript is being included in both pages? This is the one that handles the data-method attribute, turning it into a real delete request as expected when you click the link through some js handling. If it's not, that's your problem, otherwise I'll have to ask you a sample application showing the problem. Thanks!

All 3 comments

Can you double check if the rails ujs javascript is being included in both pages? This is the one that handles the data-method attribute, turning it into a real delete request as expected when you click the link through some js handling. If it's not, that's your problem, otherwise I'll have to ask you a sample application showing the problem. Thanks!

@carlosantoniodasilva you nailed it. The template used on the second page was not properly loading the rails ujs file.
I'm closing this ticket.
Thx and Happy Holidays.

Glad to hear it's not a :bug:! Happy holidays! :)

Was this page helpful?
0 / 5 - 0 ratings