Delete links stopped working data-method='delete' but goes to show page

孤街醉人 提交于 2020-01-13 05:19:31

问题


I just noticed that all the various delete links in my application now just go to show pages. This application began as rails 2.3.8, it is now rails 3.2.17

Examples of the rails code:

Controllers,

def destroy
  @group = Group.find(params[:id])
  @group.destroy    
  respond_to do |format|
    format.html { redirect_to(groups_url) }
    format.xml  { head :ok }
  end
end 

And,

def destroy
  @link = Link.find(params[:id])
  @link.destroy
  respond_to do |format|
    format.html { redirect_to(links_url) }
  end 
end 

Which generates:

HTML,

<a rel="nofollow" data-method="delete" data-confirm="Sure?" href="/groups/35">
x
</a>

And,

<a rel="nofollow" data-method="delete" data-confirm="Sure?" href="/links/8">
x
</a>

I noticed that I had,

= javascript_include_tag "application"

In my application layout template and I tried updating that to be,

= javascript_include_tag :defaults

But it didn't help with this issue, still going to show page and not deleting and worse, doing this stopped all my other javascript from working! Such as leaving user on the search field automatically, the date-picker calendar, etc.

My application.js file has:

//= require jquery-1.7.2.min
//= require jquery-ui-1.8.22.custom.min
//= require default_on_first_input_field
//= require row_shading
//= require long_or_short_details
//= require sortable_hook
//= require date-picker
//= require_self

回答1:


The answer was that I needed to add just this line:

//= require jquery_ujs

to my js manifest. This fixed it. My manifest now look like:

// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults
//
//= require jquery-1.7.2.min
//= require jquery-ui-1.8.22.custom.min
//= require jquery_ujs
//= require default_on_first_input_field
//= require row_shading
//= require long_or_short_details
//= require sortable_hook
//= require date-picker
//= require_self


来源:https://stackoverflow.com/questions/25095460/delete-links-stopped-working-data-method-delete-but-goes-to-show-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!