Ruby on rails 调用Rails GET方法而不是DELETE

Ruby on rails 调用Rails GET方法而不是DELETE,ruby-on-rails,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby On Rails 3,Ruby On Rails 4,我试图使用:method=>:delete删除一条记录,但它调用的是GET。它重定向到show并显示404 not found。但如果我返回并刷新,记录会被意外删除 <% @photos.each do |photo| %> <div class='photogallery'> <%= link_to image_tag(photo.image_url(:thumb)) if photo.image? %> <div class="name">&l

我试图使用:method=>:delete删除一条记录,但它调用的是GET。它重定向到show并显示404 not found。但如果我返回并刷新,记录会被意外删除

<% @photos.each do |photo| %>
<div class='photogallery'>
<%= link_to image_tag(photo.image_url(:thumb)) if photo.image? %>
<div class="name"><%= photo.caption %></div>
<div class="actions">
<%= link_to "edit", edit_admins_photogallery_path(photo) %> |
<%= link_to "remove",admins_photogallery_path(photo), :method => 'delete',:confirm => 'Are you sure?' %> |

</div>
</div>
<% end %>
我已经包括在我的布局文件和它被加载的罚款

<%= csrf_meta_tag %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
编辑:photogallery_controller.rb

def destroy
  @photos = Photogallery.find(params[:id])
 if @photos.destroy
  redirect_to admins_photogallery_path, notice: "Photo was successfully destroyed."
 else
  render :action => 'index'
  flash[:error] = "Photo could not be deleted."
 end
end

我相信你的设置是正确的,你只是在呼叫重定向中输入了一个错误。admins\u photogallery\u路径是显示页面。管理员路径是索引页。除非在路由中特别指定,否则不可能发出GET请求并到达destroy方法。GET和DELETE动词都指向同一条路径——如果您确实在使用GET请求,只需转到show页面,就不会发生任何事情。任何被删除的内容都表明删除请求正在成功执行。

我遇到了相同的问题,当我将link\u更改为button\u时,所有内容都开始正常工作。可能是因为link_to主要用于GET calls,button_to主要用于POST calls(在我的例子中,还包括DELETE).

我可以获取您的路由文件吗?我已经包含了路由文件。您是否启用了JS?是的,其他使用JS的功能可以正常工作。是否所有删除请求都已中断,或者只有使用此路径/资源的请求?注:这不是admins\u photogalleries\u路径,因为没有带photogalleries的控制器,取而代之的是它的管理员\u photogallery\u index\u path:)将其作为注释而不是答案添加
devise_for :users
root 'index#index'
resources :reprint
devise_scope :user do
get "/admins/", :to => "devise/sessions#new"
end
namespace :admins do
resources :location,:dashboard,:lodge,:room,:booking,:rate_calendar,:photogallery    
end  
resources :index do 
collection do
match 'search' => 'index#search', via: [:get, :post], as: :search
match 'location' => 'index#location', via: [:get, :post], as: :location
match  'add_cart' => 'index#add_cart', via: [:get, :post], as: :add_cart
end
end
resources :room_availability
def destroy
  @photos = Photogallery.find(params[:id])
 if @photos.destroy
  redirect_to admins_photogallery_path, notice: "Photo was successfully destroyed."
 else
  render :action => 'index'
  flash[:error] = "Photo could not be deleted."
 end
end
def destroy
  @photos = Photogallery.find(params[:id])
 if @photos.destroy
  redirect_to admins_photogalleries_path, notice: "Photo was successfully destroyed."
 else
  render :action => 'index'
  flash[:error] = "Photo could not be deleted."
 end
end