尝试删除AJAX请求时出错。
我认为它来自视图中的html生成器函数。
NameError in ProductsController#edit
undefined local variable or method `delete' for #<#<Class:0x000001071a0998>:0x00000108bb7bb0>
视图
<% @product.pictures.each do |p| %>
<%= image_tag p.image.url(:medium) %>
<%= link_to "Delete" , p, remote: true, method: delete %>
<% end %>
路线
resources :pictures, only: [:destroy]
的CoffeeScript
$ ->
$("a[data-remote]").on "ajax:success", (e, data, status, xhr) ->
alert "The post was deleted."
图片控制器
def delete
@picture = Picture.new(params[:user])
@picture.destroy
end
答案 0 :(得分:3)
应该是method: :delete
。 delete
不是您可以调用的方法。